Back to index

scribus-ng  1.3.4.dfsg+svn20071115
prefsdialogbase.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "prefsdialogbase.h"
00008 #include "prefsdialogbase.moc"
00009 #include <qvariant.h>
00010 #include <qpushbutton.h>
00011 #include <qlayout.h>
00012 #include <qtooltip.h>
00013 #include <qwhatsthis.h>
00014 #include <qlabel.h>
00015 #include <qfont.h>
00016 #include <qfiledialog.h>
00017 
00018 #include "commonstrings.h"
00019 #include "prefsmanager.h"
00020 
00021 
00022 extern QPixmap loadIcon(QString nam);
00023 
00024 
00025 PrefsDialogBase::PrefsDialogBase( QWidget* parent ) : QDialog( parent, "PrefsDialogBase", true, 0 )
00026 {
00027        counter = 0;
00028        setName( "PrefsDialogBase" );
00029        setIcon(loadIcon("AppIcon.png"));
00030        setSizeGripEnabled( true );
00031        prefsLayout = new QVBoxLayout( this, 11, 6, "prefsLayout");
00032        layout3 = new QHBoxLayout( 0, 0, 6, "layout3");
00033        prefsSelection = new QIconView( this, "prefsSelection" );
00034        prefsSelection->setHScrollBarMode( QIconView::AlwaysOff );
00035        prefsSelection->setVScrollBarMode( QIconView::Auto );
00036        prefsSelection->setArrangement(QIconView::LeftToRight);
00037        prefsSelection->setItemsMovable(false);
00038        prefsSelection->setAutoArrange( false );
00039        prefsSelection->setSorting( false );
00040        prefsSelection->setWordWrapIconText(false);
00041        prefsSelection->setFocusPolicy(QWidget::NoFocus);
00042        prefsSelection->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)7, 0, 0, prefsSelection->sizePolicy().hasHeightForWidth() ) );
00043        layout3->addWidget( prefsSelection );
00044        layout5 = new QVBoxLayout( 0, 0, 6, "layout5");
00045        tabNameLabel = new QLabel( this, "tabNameLabel" );
00046        QFont f(tabNameLabel->font());
00047        f.setPointSize(f.pointSize()+4);
00048        f.setBold(true);
00049        tabNameLabel->setFont(f);
00050        tabNameLabel->setText("");
00051        layout5->addWidget( tabNameLabel );
00052        prefsWidgets = new QWidgetStack( this, "prefsWidgets" );
00053        layout5->addWidget( prefsWidgets );
00054        layout3->addLayout(layout5);
00055        prefsLayout->addLayout( layout3 );
00056        layout4 = new QHBoxLayout( 0, 0, 6, "layout4");
00057        saveButton = new QPushButton(this, "saveButton");
00058        saveButton->setAutoDefault( false );
00059        saveButton->setDefault( false );
00060        layout4->addWidget(saveButton);
00061        QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00062        layout4->addItem( spacer );
00063        backToDefaults = new QPushButton( this, "backToDefaults" );
00064        backToDefaults->setAutoDefault( false );
00065        backToDefaults->setDefault( false );
00066        layout4->addWidget( backToDefaults );
00067        applyChangesButton = new QPushButton( this, "applyChangesButton" );
00068        applyChangesButton->setAutoDefault( false );
00069        applyChangesButton->setDefault( false );
00070        layout4->addWidget( applyChangesButton );
00071        buttonOk = new QPushButton( this, "buttonOk" );
00072        buttonOk->setAutoDefault( false );
00073        buttonOk->setDefault( false );
00074        layout4->addWidget( buttonOk );
00075        buttonCancel = new QPushButton( this, "buttonCancel" );
00076        buttonCancel->setAutoDefault( false );
00077        buttonCancel->setDefault( false );
00078        layout4->addWidget( buttonCancel );
00079        prefsLayout->addLayout( layout4 );
00080        languageChange();
00081        connect(prefsSelection, SIGNAL(clicked(QIconViewItem *)), this, SLOT(itemSelected(QIconViewItem* )));
00082        connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
00083        connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
00084        connect(saveButton, SIGNAL(clicked()), this, SLOT(saveButton_clicked()));
00085 }
00086 
00087 int PrefsDialogBase::addItem(QString name, QPixmap icon, QWidget *tab)
00088 {
00089        QIconViewItem* icx = new QIconViewItem(prefsSelection, name, icon);
00090        prefsWidgets->addWidget(tab, counter);
00091        icx->setDragEnabled(false);
00092        itemMap.insert(icx, counter);
00093        counter++;
00094        return counter-1;
00095 }
00096 
00097 void PrefsDialogBase::arrangeIcons()
00098 {
00099        int maxWidth = 0;
00100        QIconViewItem* ic = prefsSelection->firstItem();
00101        int startY = 5;
00102        for (uint cc = 0; cc < prefsSelection->count(); ++cc)
00103        {
00104               int w = ic->width();
00105               maxWidth = QMAX(w, maxWidth);
00106               ic = ic->nextItem();
00107        }
00108        ic = prefsSelection->firstItem();
00109        prefsSelection->setAutoArrange( false );
00110        prefsSelection->setResizeMode(QIconView::Fixed);
00111        for (uint cc = 0; cc < prefsSelection->count(); ++cc)
00112        {
00113               int w = ic->width();
00114               int moveW = (maxWidth - w) / 2;
00115               ic->move(moveW, startY);
00116               startY += ic->height()+5;
00117               ic = ic->nextItem();
00118        }
00119 }
00120 
00121 void PrefsDialogBase::itemSelected(QIconViewItem* ic)
00122 {
00123        if (ic == 0)
00124               return;
00125        if (itemMap.contains(ic))
00126        {
00127               prefsWidgets->raiseWidget(itemMap[ic]);
00128               tabNameLabel->setText(ic->text());
00129        }
00130 }
00131 /*
00132  *  Sets the strings of the subwidgets using the current
00133  *  language.
00134  */
00135 void PrefsDialogBase::languageChange()
00136 {
00137        buttonOk->setText( CommonStrings::tr_OK );
00138        buttonCancel->setText( CommonStrings::tr_Cancel );
00139        saveButton->setText( tr("Export..."));
00140        backToDefaults->setText( tr( "&Defaults" ) );
00141        applyChangesButton->setText( tr("&Apply"));
00142        QToolTip::add(backToDefaults, "<qt>" + tr("All preferences can be reset here") + "</qt>");
00143        QToolTip::add(applyChangesButton, "<qt>" + tr("Apply all changes without closing the dialog") + "</qt>");
00144        QToolTip::add(saveButton, "<qt>" + tr("Export current preferences into file") + "</qt>");
00145 }
00146 
00147 void PrefsDialogBase::saveButton_clicked()
00148 {
00149        QString s = QFileDialog::getSaveFileName(
00150                      QDir::currentDirPath(),
00151                      "All Files (*)",
00152                      this,
00153                      "save prefs",
00154                      tr("Save Preferences"));
00155        if (s.isEmpty())
00156               return;
00157        PrefsManager *pm = PrefsManager::instance();
00158        pm->SavePrefs(s);
00159 }