size grip for login;
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 31 Dec 2010 15:48:37 +0000 (15:48 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 31 Dec 2010 15:48:37 +0000 (15:48 +0000)
configurable help menu

git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@699 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/dialogs/login.cpp
src/dialogs/login.h
src/main.cpp
src/main.h

index 2dfada3..f389c51 100644 (file)
@@ -28,6 +28,7 @@
 #include <QMessageBox>
 #include <QPushButton>
 #include <QSettings>
+#include <QSizeGrip>
 
 MLogin::MLogin()
 {
@@ -68,6 +69,8 @@ MLogin::MLogin()
        QPushButton*p;
        hl->addStretch(10);
        hl->addWidget(p=new QPushButton(tr("Login")),0);
+       vl->addLayout(hl=new QHBoxLayout);
+       resizer=new QSizeGrip(this);
        connect(p,SIGNAL(clicked()),this,SLOT(startLogin()));
        initProfiles();
        loadProfile();
@@ -140,3 +143,13 @@ void MLogin::configwin()
        initProfiles();
        loadProfile();
 }
+
+void MLogin::resizeEvent(QResizeEvent* )
+{
+       resizer->resize(resizer->sizeHint());
+       if (isRightToLeft())
+               resizer->move(rect().bottomLeft() -resizer->rect().bottomLeft());
+       else
+               resizer->move(rect().bottomRight() -resizer->rect().bottomRight());
+       resizer->raise();
+}
index 5929ac2..04d9d66 100644 (file)
@@ -17,6 +17,7 @@
 
 class QComboBox;
 class QLineEdit;
+class QSizeGrip;
 
 /**login and profile configuration window*/
 class MLogin:public QWidget
@@ -29,6 +30,10 @@ class MLogin:public QWidget
                QString sessionid;
                QLineEdit*username,*password;
                QComboBox*profiles;
+               QSizeGrip*resizer;
+               
+       protected:
+               void resizeEvent(QResizeEvent *);
                
        private slots:
                void initProfiles();
index c05c65e..f7ded2d 100644 (file)
@@ -12,6 +12,8 @@
 
 #include <QDesktopServices>
 #include <QDir>
+#include <QDomDocument>
+#include <QDomElement>
 #include <QHostInfo>
 #include <QIcon>
 #include <QInputDialog>
@@ -19,6 +21,7 @@
 #include <QMenu>
 #include <QMessageBox>
 #include <QSettings>
+#include <QSignalMapper>
 #include <QTranslator>
 #include <QUrl>
 
@@ -62,7 +65,7 @@ QString dataDir;
 
 #include <stdlib.h>
 
-void initDataDir()
+static void initDataDir()
 {
 #ifdef Q_OS_WIN32
        dataDir=getenv("APPDATA");
@@ -74,15 +77,7 @@ void initDataDir()
        dataDir+="/.magicSmoke2";
 }
 
-QMenu* MApplication::helpMenu()
-{
-       QMenu*m=new QMenu(tr("&Help"));
-       m->addAction("&Help",qApp,SLOT(help()));
-       m->addSeparator();
-       m->addAction("About &MagicSmoke",qApp,SLOT(aboutMS()));
-       m->addAction("About &Qt",qApp,SLOT(aboutQt()));
-       return m;
-}
+#define HOMEPAGE_BASEURL "http://smoke.silmor.de"
 
 void MApplication::aboutMS()
 {
@@ -90,10 +85,10 @@ void MApplication::aboutMS()
        mb.setIconPixmap(QPixmap(":/icon.png"));
        mb.setWindowTitle(tr("About MagicSmoke"));
        mb.setText(tr(  "<h3>MagicSmoke %3</h3>"
-                       "&copy; Konrad Rosenbaum, 2007-2010<br>"
+                       "&copy; Konrad Rosenbaum, 2007-2011<br>"
                        "&copy; Peter Keller, 2007-2008<br>"
                        "protected under the GNU GPL v.3 or at your option any newer<p>"
-                       "See also the <a href=\"http://smoke.silmor.de\">MagicSmoke Homepage</a>.<p>"
+                       "See also the <a href=\"" HOMEPAGE_BASEURL "\">MagicSmoke Homepage</a>.<p>"
                        "This version was compiled from repository '%1' revision '%2'.").
                        arg(MSInterface::repoPart()). // %1
                        arg(MInterface::svnVersion()). //%2
@@ -103,18 +98,74 @@ void MApplication::aboutMS()
        mb.exec();
 }
 
+static QList<QPair<QString,QString> > helpUrl;
+
+static void initHelpUrl()
+{
+       //check file exists, if not initialize it
+       QFile fd(dataDir+"/helpMenu.xml");
+       if(!fd.exists()){
+               fd.open(QIODevice::WriteOnly);
+               fd.write(QByteArray("<HelpMenu>\n\t<Item label=\"&amp;Help\">default://</Item>\n</HelpMenu>"));
+               fd.close();
+       };
+       //try to open
+       if(fd.open(QIODevice::ReadOnly)){
+               //read config
+               QDomDocument doc;
+               doc.setContent(&fd);
+               QDomNodeList nl=doc.elementsByTagName("Item");
+               for(int i=0;i<nl.size();i++){
+                       QDomElement el=nl.at(i).toElement();
+                       helpUrl.append(QPair<QString,QString>(el.attribute("label").trimmed(), el.text().trimmed()));
+               }
+       }
+       //fallback
+       if(helpUrl.size()<1)
+               helpUrl<<QPair<QString,QString>("&Help","default://");
+}
+
+QMenu* MApplication::helpMenu()
+{
+       QMenu*m=new QMenu(tr("&Help"));
+       QSignalMapper *map=new QSignalMapper(m);
+       connect(map,SIGNAL(mapped(int)),qApp,SLOT(help(int)));
+       for(int i=0;i<helpUrl.size();i++){
+               QAction*a=m->addAction(helpUrl[i].first,map,SLOT(map()));
+               map->setMapping(a,i);
+       }
+       m->addSeparator();
+       m->addAction("About &MagicSmoke",qApp,SLOT(aboutMS()));
+       m->addAction("About &Qt",qApp,SLOT(aboutQt()));
+       return m;
+}
+
 void MApplication::help()
 {
        QString d=QApplication::applicationDirPath()+"/doc/index.html";
        if(!QFile(d).exists()){
-               d="http://smoke.silmor.de/doc/"+MSInterface::repoPart()+"/index.html";
+               d=HOMEPAGE_BASEURL "/doc/"+MSInterface::repoPart()+"/index.html";
        }else d="file:///"+d;
        QDesktopServices::openUrl(QUrl(d));
 }
 
+void MApplication::help(int idx)
+{
+       if(idx<0 || idx>=helpUrl.size()){
+               help();
+               return;
+       }
+       QString url=helpUrl[idx].second;
+       if(url=="default://" || url=="")
+               help();
+       else
+               QDesktopServices::openUrl(QUrl(url));
+}
+
 MApplication::MApplication(int&ac,char**av)
 :QApplication(ac,av)
-{}
+{
+}
 
 void MApplication::setMyStyle()
 {
@@ -173,6 +224,9 @@ int main(int argc,char**argv)
        //initialize log file
        initDebug();
        
+       //init help menu layout
+       initHelpUrl();
+       
        //check/generate profile
        if(!QSettings().childGroups().contains("profiles")){
                QMessageBox::warning(0,app.translate("initprofile","Initial Profile Warning"), app.translate("initprofile","You need a profile to work with Magic Smoke. Please create one now."));
index d22bfcc..488a35f 100644 (file)
@@ -37,6 +37,7 @@ class MApplication:public QApplication
                //help menu
                void aboutMS();
                void help();
+               void help(int);
 };
 
 #endif