made style and stylesheet selectable
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sat, 26 Dec 2009 18:20:27 +0000 (18:20 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sat, 26 Dec 2009 18:20:27 +0000 (18:20 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@354 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/dialogs/configdialog.cpp
src/dialogs/configdialog.h
src/main.cpp
src/main.h

index 4dc2116..f3f0750 100644 (file)
@@ -39,6 +39,7 @@
 #include <QSettings>
 #include <QSpinBox>
 #include <QStandardItemModel>
+#include <QStyleFactory>
 #include <QTableView>
 #include <QTimer>
 #include <QUrl>
@@ -72,6 +73,7 @@ MConfigDialog::MConfigDialog()
        m->addAction(tr("&Language..."),this,SLOT(changeLang()));
        m->addAction(tr("&OpenOffice.org Settings..."),this,SLOT(openOfficeCfg()));
        m->addAction(tr("Set &Default Label Font..."),this,SLOT(setDefaultFont()));
+       m->addAction(tr("Set &Application Style..."),this,SLOT(setAppStyle()));
        mb->addMenu(MApplication::helpMenu());
        
        //create list view
@@ -475,6 +477,12 @@ void MConfigDialog::setDefaultFont()
        QSettings().setValue("defaultfont",df);
 }
 
+void MConfigDialog::setAppStyle()
+{
+       MAppStyleDialog d(this);
+       d.exec();
+}
+
 void MConfigDialog::serverProbe()
 {
        //sanity check
@@ -546,3 +554,53 @@ void MConfigDialog::sslFillModel()
                sslmodel->setData(sslmodel->index(i,2),QSslError((QSslError::SslError)lst[i].second).errorString());
        }
 }
+
+MAppStyleDialog::MAppStyleDialog(QWidget*par)
+       :QDialog(par)
+{
+       setWindowTitle(tr("Application Style"));
+       QGridLayout *gl;
+       setLayout(gl=new QGridLayout);
+       gl->addWidget(new QLabel(tr("GUI Style:")),0,0);
+       gl->addWidget(style=new QComboBox,0,1,1,2);
+       style->addItem(tr("System Default"));
+       style->setEditable(false);
+       QStringList k=QStyleFactory::keys();
+       QString cs=QSettings().value("appstyle").toString();
+       style->addItems(k);
+       if(k.contains(cs))
+               style->setCurrentIndex(k.indexOf(cs)+1);
+       
+       gl->addWidget(new QLabel(tr("Stylesheet:")),1,0);
+       gl->addWidget(css=new QLineEdit,1,1);
+       css->setText(QSettings().value("appstylesheet").toString());
+       QPushButton*p;
+       gl->addWidget(p=new QPushButton("..."),1,2);
+       connect(p,SIGNAL(clicked()),this,SLOT(selectCSS()));
+       
+       gl->setRowMinimumHeight(2,15);
+       QHBoxLayout*hl;
+       gl->addLayout(hl=new QHBoxLayout,3,0,1,3);
+       hl->addStretch(10);
+       hl->addWidget(p=new QPushButton(tr("Ok")));
+       connect(p,SIGNAL(clicked()),this,SLOT(accept()),Qt::QueuedConnection);
+       connect(p,SIGNAL(clicked()),this,SLOT(save()));
+       hl->addWidget(p=new QPushButton(tr("Cancel")));
+       connect(p,SIGNAL(clicked()),this,SLOT(reject()));
+}
+
+void MAppStyleDialog::selectCSS()
+{
+       QString s=QFileDialog::getOpenFileName(this,tr("Select Stylesheet"));
+       if(s!="")css->setText(s);
+}
+
+void MAppStyleDialog::save()
+{
+       if(style->currentIndex()==0)
+               QSettings().remove("appstyle");
+       else
+               QSettings().setValue("appstyle",style->currentText());
+       QSettings().setValue("appstylesheet",css->text());
+}
+
index 279653a..c5fe29e 100644 (file)
@@ -67,6 +67,7 @@ class MConfigDialog:public QDialog
                void generateKey();
                void openOfficeCfg();
                void setDefaultFont();
+               void setAppStyle();
                //ssl server probe
                void serverProbe();
                void sslErrors(QNetworkReply*,const QList<QSslError>&);
@@ -74,4 +75,20 @@ class MConfigDialog:public QDialog
                void sslFillModel();
 };
 
+class QComboBox;
+class QLineEdit;
+
+class MAppStyleDialog:public QDialog
+{
+       Q_OBJECT
+       public:
+               MAppStyleDialog(QWidget*);
+       private slots:
+               void selectCSS();
+               void save();
+       private:
+               QComboBox*style;
+               QLineEdit*css;
+};
+
 #endif
index 0337b93..63740c7 100644 (file)
@@ -112,6 +112,23 @@ void MApplication::help()
        QDesktopServices::openUrl(QUrl(d));
 }
 
+MApplication::MApplication(int ac,char**av)
+:QApplication(ac,av)
+{}
+
+void MApplication::setMyStyle()
+{
+       QSettings set;
+       if(set.contains("appstyle"))
+               setStyle(set.value("appstyle").toString());
+       if(set.contains("appstylesheet")){
+               QFile fd(set.value("appstylesheet").toString());
+               if(fd.open(QIODevice::ReadOnly)){
+                       setStyleSheet(QString::fromLocal8Bit(fd.readAll()));
+                       fd.close();
+               }
+       }
+}
 
 int main(int argc,char**argv)
 {
@@ -125,6 +142,9 @@ int main(int argc,char**argv)
        //set icon
        app.setWindowIcon(QIcon(":/icon.png"));
        
+       //set styling
+       app.setMyStyle();
+       
        //install event filter for random generator
        EFilter ef;
        app.installEventFilter(&ef);
index c5f3c0b..caa19d5 100644 (file)
@@ -28,7 +28,9 @@ class MApplication:public QApplication
 {
        Q_OBJECT
        public:
-               MApplication(int ac,char**av):QApplication(ac,av){}
+               MApplication(int ac,char**av);
+               
+               void setMyStyle();
                
                static QMenu*helpMenu();
        public slots: