diff --git a/Makefile.am b/Makefile.am index b3a3c77ae..62d7c94e2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -46,11 +46,8 @@ apps_DATA = kdvi.desktop bin_SCRIPTS = kdvi -#partdir = $(kde_datadir)/kdvi -#part_DATA = kdvi_part.rc - -#rcdir = $(kde_datadir)/kdvi -#rc_DATA = kdvi.rc +partdir = $(kde_datadir)/kdvi +part_DATA = kdvi_part.rc psheader.c: psheader.txt squeeze ./squeeze $(srcdir)/psheader.txt $@ diff --git a/kdvi_multipage.cpp b/kdvi_multipage.cpp index 69f49e971..be50bed71 100644 --- a/kdvi_multipage.cpp +++ b/kdvi_multipage.cpp @@ -9,8 +9,11 @@ #include #include #include +#include +#include +#include "optiondialog.h" #include "kdvi_multipage.moc" @@ -57,11 +60,18 @@ KInstance *KDVIMultiPageFactory::instance() KDVIMultiPage::KDVIMultiPage(QWidget *parent, const char *name) - : KMultiPage(parent, name), window(0) + : KMultiPage(parent, name), window(0), options(0) { setInstance(KDVIMultiPageFactory::instance()); window = new dviWindow(300, 1.0, "cx", 0, scrollView()); + preferencesChanged(); + + new KAction(i18n("&DVI Options"), 0, this, + SLOT(doSettings()), actionCollection(), + "settings_dvi"); + + setXMLFile("kdvi_part.rc"); scrollView()->addChild(window); } @@ -151,3 +161,57 @@ bool KDVIMultiPage::preview(QPainter *p, int w, int h) return true; } + + +void KDVIMultiPage::doSettings() +{ + if (options) + { + options->show(); + return; + } + + options = new OptionDialog(window); + connect(options, SIGNAL(preferencesChanged()), this, SLOT(preferencesChanged())); + options->show(); +} + + +void KDVIMultiPage::preferencesChanged() +{ + KConfig *config = KGlobal::config(); + + QString s; + + config->setGroup( "kdvi" ); + + s = config->readEntry( "FontPath" ); + if ( !s.isEmpty() && s != window->fontPath() ) + window->setFontPath( s ); + + int basedpi = config->readNumEntry( "BaseResolution" ); + if ( basedpi <= 0 ) + config->writeEntry( "BaseResolution", basedpi = 300 ); + if ( basedpi != window->resolution() ) + window->setResolution( basedpi ); + + QString mfmode = config->readEntry( "MetafontMode" ); + if ( mfmode.isNull() ) + config->writeEntry( "MetafontMode", mfmode = "/" ); + if ( mfmode != window->metafontMode() ) + window->setMetafontMode( mfmode ); + + s = config->readEntry( "Gamma" ); + if ( !s.isEmpty() && s.toFloat() != window->gamma() ) + window->setGamma( s.toFloat() ); + + int makepk = config->readNumEntry( "MakePK" ); + if ( makepk != window->makePK() ) + window->setMakePK( makepk ); + + int showPS = config->readNumEntry( "ShowPS" ); + if (showPS != window->showPS()) + window->setShowPS(showPS); + + window->setAntiAlias( config->readNumEntry( "PS Anti Alias", 1 ) ); +} diff --git a/kdvi_multipage.h b/kdvi_multipage.h index e9c9bac52..322641bbc 100644 --- a/kdvi_multipage.h +++ b/kdvi_multipage.h @@ -12,6 +12,7 @@ class QLabel; class QPainter; +class OptionDialog; #include @@ -85,9 +86,17 @@ signals: /// emitted to indicate the number of pages in the file void numberOfPages(int nr); + +protected slots: + + void doSettings(); + void preferencesChanged(); + + private: dviWindow *window; + OptionDialog *options; }; diff --git a/kdvi_part.rc b/kdvi_part.rc index 611090f81..3d484bfff 100644 --- a/kdvi_part.rc +++ b/kdvi_part.rc @@ -1,17 +1,8 @@ - + - &View - - - - - - - - - + &Settings + - diff --git a/optiondialog.cpp b/optiondialog.cpp index 6e21dc7dc..e813f391f 100644 --- a/optiondialog.cpp +++ b/optiondialog.cpp @@ -31,152 +31,17 @@ #include #include #include +#include #include "optiondialog.h" - -static const char *paperNames[] = -{ - "US", - "US landscape", - "Legal", - "foolscap", - - // ISO `A' formats, Portrait - "A1", - "A2", - "A3", - "A4", - "A5", - "A6", - "A7", - - // ISO `A' formats, Landscape - "A1 landscape", - "A2 landscape", - "A3 landscape", - "A4 landscape", - "A5 landscape", - "A6 landscape", - "A7 landscape", - - // ISO `B' formats, Portrait - "B1", - "B2", - "B3", - "B4", - "B5", - "B6", - "B7", - - // ISO `B' formats, Landscape - "B1 landscape", - "B2 landscape", - "B3 landscape", - "B4 landscape", - "B5 landscape", - "B6 landscape", - "B7 landscape", - - // ISO `C' formats, Portrait - "C1", - "C2", - "C3", - "C4", - "C5", - "C6", - "C7", - - // ISO `C' formats, Landscape - "C1 landscape", - "C2 landscape", - "C3 landscape", - "C4 landscape", - "C5 landscape", - "C6 landscape", - "C7 landscape", - - 0 -}; - - -static const char *papers[] = -{ - "us", "8.5x11", - "usr", "11x8.5", - "legal", "8.5x14", - "foolscap", "13.5x17.0", /* ??? */ - - // ISO `A' formats, Portrait - "a1", "59.4x84.0cm", - "a2", "42.0x59.4cm", - "a3", "29.7x42.0cm", - "a4", "21.0x29.7cm", - "a5", "14.85x21.0cm", - "a6", "10.5x14.85cm", - "a7", "7.42x10.5cm", - - // ISO `A' formats, Landscape - "a1r", "84.0x59.4cm", - "a2r", "59.4x42.0cm", - "a3r", "42.0x29.7cm", - "a4r", "29.7x21.0cm", - "a5r", "21.0x14.85cm", - "a6r", "14.85x10.5cm", - "a7r", "10.5x7.42cm", - - // ISO `B' formats, Portrait - "b1", "70.6x100.0cm", - "b2", "50.0x70.6cm", - "b3", "35.3x50.0cm", - "b4", "25.0x35.3cm", - "b5", "17.6x25.0cm", - "b6", "13.5x17.6cm", - "b7", "8.8x13.5cm", - - // ISO `B' formats, Landscape - "b1r", "100.0x70.6cm", - "b2r", "70.6x50.0cm", - "b3r", "50.0x35.3cm", - "b4r", "35.3x25.0cm", - "b5r", "25.0x17.6cm", - "b6r", "17.6x13.5cm", - "b7r", "13.5x8.8cm", - - // ISO `C' formats, Portrait - "c1", "64.8x91.6cm", - "c2", "45.8x64.8cm", - "c3", "32.4x45.8cm", - "c4", "22.9x32.4cm", - "c5", "16.2x22.9cm", - "c6", "11.46x16.2cm", - "c7", "8.1x11.46cm", - - // ISO `C' formats, Landscape - "c1r", "91.6x64.8cm", - "c2r", "64.8x45.8cm", - "c3r", "45.8x32.4cm", - "c4r", "32.4x22.9cm", - "c5r", "22.9x16.2cm", - "c6r", "16.2x11.46cm", - "c7r", "11.46x8.1cm", - - 0 -}; - - - - - OptionDialog::OptionDialog( QWidget *parent, const char *name, bool modal ) :KDialogBase( Tabbed, i18n("Preferences"), Help|Ok|Apply|Cancel, Ok, parent, name, modal ) { makeFontPage(); makeRenderingPage(); - makePaperPage(); - makeMiscPage(); } @@ -199,25 +64,19 @@ void OptionDialog::slotOk() void OptionDialog::slotApply() { - KConfig &config = *kapp->config(); - config.setGroup("kdvi"); - - config.writeEntry( "BaseResolution", mFont.resolutionEdit->text() ); - config.writeEntry( "MetafontMode", mFont.metafontEdit->text() ); - config.writeEntry( "MakePK", mFont.fontPathCheck->isChecked() ); - config.writeEntry( "FontPath", mFont.fontPathEdit->text() ); - config.writeEntry( "SmallZoom", mFont.zoomSmallEdit->text() ); - config.writeEntry( "LargeZoom", mFont.zoomLargeEdit->text() ); + KConfig *config = KGlobal::config(); + config->setGroup("kdvi"); - config.writeEntry( "ShowPS", mRender.showSpecialCheck->isChecked() ); - config.writeEntry( "PS Anti Alias", mRender.antialiasCheck->isChecked() ); - config.writeEntry( "Gamma", mRender.gammaEdit->text() ); + config->writeEntry( "BaseResolution", mFont.resolutionEdit->text() ); + config->writeEntry( "MetafontMode", mFont.metafontEdit->text() ); + config->writeEntry( "MakePK", mFont.fontPathCheck->isChecked() ); + config->writeEntry( "FontPath", mFont.fontPathEdit->text() ); - QString paperText = mPaper.paperCombo->currentText(); - config.writeEntry( "Paper", paperText.simplifyWhiteSpace() ); + config->writeEntry( "ShowPS", mRender.showSpecialCheck->isChecked() ); + config->writeEntry( "PS Anti Alias", mRender.antialiasCheck->isChecked() ); + config->writeEntry( "Gamma", mRender.gammaEdit->text() ); - config.setGroup("RecentFiles"); - config.writeEntry( "MaxCount", mMisc.recentSpin->value() ); + config->sync(); emit preferencesChanged(); } @@ -225,47 +84,20 @@ void OptionDialog::slotApply() void OptionDialog::setup() { - KConfig &config = *kapp->config(); - config.setGroup("kdvi"); + KConfig *config = KGlobal::config(); + config->setGroup("kdvi"); // Font page - mFont.resolutionEdit->setText( config.readEntry( "BaseResolution" ) ); - mFont.metafontEdit->setText( config.readEntry( "MetafontMode" ) ); - mFont.fontPathCheck->setChecked( config.readNumEntry( "MakePK" ) ); - mFont.fontPathEdit->setText( config.readEntry( "FontPath" ) ); - mFont.zoomSmallEdit->setText( config.readEntry( "SmallZoom" ) ); - mFont.zoomLargeEdit->setText( config.readEntry( "LargeZoom" ) ); + mFont.resolutionEdit->setText( config->readEntry( "BaseResolution" ) ); + mFont.metafontEdit->setText( config->readEntry( "MetafontMode" ) ); + mFont.fontPathCheck->setChecked( config->readNumEntry( "MakePK" ) ); + mFont.fontPathEdit->setText( config->readEntry( "FontPath" ) ); fontPathCheckChanged( mFont.fontPathCheck->isChecked() ); // Rendering page - mRender.showSpecialCheck->setChecked( config.readNumEntry( "ShowPS" ) ); - mRender.antialiasCheck->setChecked(config.readNumEntry("PS Anti Alias", 1)); - mRender.gammaEdit->setText( config.readEntry( "Gamma" ) ); - - // Paper page - QString paperText = config.readEntry( "Paper" ); - if( mPaper.paperCombo->currentText() != paperText ) - { - bool match = false; - for( int i=0; icount() && papers[i*2] != 0; i++ ) - { - if( paperText == mPaper.paperCombo->text(i) || paperText == papers[i*2] ) - { - match = true; - mPaper.paperCombo->setCurrentItem(i); - break; - } - } - if( match == false ) - { - mPaper.paperCombo->insertItem( paperText, 0 ); - mPaper.paperCombo->setCurrentItem(0); - } - } - - // Misc page - config.setGroup("RecentFiles"); - mMisc.recentSpin->setValue( config.readEntry( "MaxCount", "5" ).toInt() ); + mRender.showSpecialCheck->setChecked( config->readNumEntry( "ShowPS" ) ); + mRender.antialiasCheck->setChecked(config->readNumEntry("PS Anti Alias", 1)); + mRender.gammaEdit->setText( config->readEntry( "Gamma" ) ); } @@ -299,18 +131,6 @@ void OptionDialog::makeFontPage() glay->addWidget( mFont.fontPathLabel, 4, 0 ); glay->addWidget( mFont.fontPathEdit, 4, 1 ); - glay->addRowSpacing( 5, spacingHint()*2 ); - - label = new QLabel( i18n("Zoom factor for small text:"), page ); - mFont.zoomSmallEdit = new QLineEdit( page ); - glay->addWidget( label, 6, 0 ); - glay->addWidget( mFont.zoomSmallEdit, 6, 1 ); - - label = new QLabel( i18n("Zoom factor for large text:"), page ); - mFont.zoomLargeEdit = new QLineEdit( page ); - glay->addWidget( label, 7, 0 ); - glay->addWidget( mFont.zoomLargeEdit, 7, 1 ); - topLayout->addStretch(1); } @@ -338,40 +158,6 @@ void OptionDialog::makeRenderingPage() } -void OptionDialog::makePaperPage() -{ - QFrame *page = addPage( i18n("Paper") ); - QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() ); - mPaper.pageIndex = pageIndex(page); - - QLabel *label = new QLabel( i18n("Select paper size:"), page ); - topLayout->addWidget( label ); - - mPaper.paperCombo = new QComboBox( false, page ); - topLayout->addWidget( mPaper.paperCombo ); - mPaper.paperCombo->insertStrList ( paperNames ); - - topLayout->addStretch(1); -} - - -void OptionDialog::makeMiscPage() -{ - QFrame *page = addPage( i18n("Miscellaneous") ); - QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() ); - mMisc.pageIndex = pageIndex(page); - - QHBoxLayout *hlay = new QHBoxLayout( topLayout ); - QLabel *label = new QLabel( i18n("Number of recent files:"), page ); - hlay->addWidget( label ); - - mMisc.recentSpin = new QSpinBox( 0, 100, 1, page ); - hlay->addWidget( mMisc.recentSpin ); - - topLayout->addStretch(1); -} - - void OptionDialog::fontPathCheckChanged( bool state ) { mFont.fontPathLabel->setEnabled( state ); @@ -379,28 +165,3 @@ void OptionDialog::fontPathCheckChanged( bool state ) } -bool OptionDialog::paperSizes( const char *p, float &w, float &h ) -{ - QString s(p); - s = s.simplifyWhiteSpace(); - - for( uint i=0; paperNames[i] != 0; i++ ) - { - if( s == paperNames[i] ) - { - s = papers[ 2*i + 1 ]; - int cm = s.findRev( "cm" ); - w = s.toFloat(); - int ind = s.find( 'x' ); - if ( ind<0 ) - return false; - s = s.mid( ind + 1, 9999 ); - h = s.toFloat(); - if ( cm >= 0 ) - w /= 2.54, h /= 2.54; - return true; - } - } - return false; -} - diff --git a/optiondialog.h b/optiondialog.h index 786fb0ebb..c3a844354 100644 --- a/optiondialog.h +++ b/optiondialog.h @@ -42,8 +42,6 @@ class OptionDialog : public KDialogBase QCheckBox *fontPathCheck; QLabel *fontPathLabel; QLineEdit *fontPathEdit; - QLineEdit *zoomSmallEdit; - QLineEdit *zoomLargeEdit; }; struct RenderItems @@ -54,18 +52,6 @@ class OptionDialog : public KDialogBase QLineEdit *gammaEdit; }; - struct PaperItems - { - int pageIndex; - QComboBox *paperCombo; - }; - - struct MiscItems - { - int pageIndex; - QSpinBox *recentSpin; - }; - public: OptionDialog( QWidget *parent=0, const char *name=0, bool modal=true); virtual void show(); @@ -79,8 +65,6 @@ class OptionDialog : public KDialogBase void setup(); void makeFontPage(); void makeRenderingPage(); - void makePaperPage(); - void makeMiscPage(); private slots: void fontPathCheckChanged( bool state ); @@ -91,8 +75,6 @@ class OptionDialog : public KDialogBase private: FontItems mFont; RenderItems mRender; - PaperItems mPaper; - MiscItems mMisc; };