GCI task: describez
authorOranger
Sat, 03 Dec 2011 14:36:36 +0100
changeset 6477 ad5741c252b9
parent 6476 afb7ef0c1c6e
child 6478 752d4fb5e376
GCI task: describez
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/ui/mouseoverfilter.cpp
QTfrontend/ui/mouseoverfilter.h
QTfrontend/ui/page/AbstractPage.cpp
QTfrontend/ui/page/AbstractPage.h
QTfrontend/ui/page/pagemain.cpp
project_files/hedgewars.pro
--- a/QTfrontend/hwform.cpp	Sat Dec 03 12:00:32 2011 +0100
+++ b/QTfrontend/hwform.cpp	Sat Dec 03 14:36:36 2011 +0100
@@ -82,6 +82,7 @@
 #include "bgwidget.h"
 #include "xfire.h"
 #include "drawmapwidget.h"
+#include "mouseoverfilter.h"
 
 #include "HWDataManager.h"
 
@@ -282,6 +283,23 @@
        wBackground->startAnimation();
     }
 
+    //Install all eventFilters :
+
+    MouseOverFilter *filter = new MouseOverFilter();
+    filter->setUi(&ui);
+
+    QList<QWidget *> widgets;
+
+    for (int i=0; i < ui.Pages->count(); i++)
+    {
+        widgets = ui.Pages->widget(i)->findChildren<QWidget *>();
+
+        for (int i=0; i < widgets.size(); i++)
+        {
+            widgets.at(i)->installEventFilter(filter);
+        }
+    }
+
     PagesStack.push(ID_PAGE_MAIN);
     GoBack();
 }
--- a/QTfrontend/hwform.h	Sat Dec 03 12:00:32 2011 +0100
+++ b/QTfrontend/hwform.h	Sat Dec 03 14:36:36 2011 +0100
@@ -61,6 +61,8 @@
     void updateXfire();
     void PlayDemoQuick(const QString & demofilename);
     void exit();
+    void setButtonDescription(QString desc);
+    void backDescription();
 
 private slots:
     void GoToSaves();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/ui/mouseoverfilter.cpp	Sat Dec 03 14:36:36 2011 +0100
@@ -0,0 +1,48 @@
+#include "mouseoverfilter.h"
+#include "ui/page/AbstractPage.h"
+#include "ui_hwform.h"
+
+#include <QEvent>
+#include <QWidget>
+#include <QStackedLayout>
+#include <QLabel>
+
+MouseOverFilter::MouseOverFilter(QObject *parent) :
+    QObject(parent)
+{
+}
+
+bool MouseOverFilter::eventFilter( QObject *dist, QEvent *event )
+{
+    if (event->type() == QEvent::Enter)
+    {
+        QWidget * widget = dynamic_cast<QWidget*>(dist);
+
+        abstractpage = qobject_cast<AbstractPage*>(ui->Pages->currentWidget());
+
+        if (widget->whatsThis() != NULL)
+            abstractpage->setButtonDescription(widget->whatsThis());
+        else if (widget->toolTip() != NULL)
+            abstractpage->setButtonDescription(widget->toolTip());
+
+        return true;
+    }
+    else if (event->type() == QEvent::Leave)
+    {
+        abstractpage = qobject_cast<AbstractPage*>(ui->Pages->currentWidget());
+
+        if (abstractpage->getDefautDescription() != NULL)
+        {
+            abstractpage->setButtonDescription( * abstractpage->getDefautDescription());
+        }
+        else
+            abstractpage->setButtonDescription("");
+    }
+
+    return false;
+}
+
+void MouseOverFilter::setUi(Ui_HWForm *uiForm)
+{
+    ui = uiForm;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/ui/mouseoverfilter.h	Sat Dec 03 14:36:36 2011 +0100
@@ -0,0 +1,27 @@
+#ifndef MOUSEOVERFILTER_H
+#define MOUSEOVERFILTER_H
+
+#include <QObject>
+
+#include "ui_hwform.h"
+#include "ui/page/AbstractPage.h"
+
+class MouseOverFilter : public QObject
+{
+    Q_OBJECT
+public:
+    explicit MouseOverFilter(QObject *parent = 0);
+    void setUi(Ui_HWForm *uiForm);
+protected:
+    bool eventFilter( QObject *dist, QEvent *event );
+signals:
+
+public slots:
+
+private:
+    Ui_HWForm *ui;
+    AbstractPage* abstractpage;
+
+};
+
+#endif // MOUSEOVERFILTER_H
--- a/QTfrontend/ui/page/AbstractPage.cpp	Sat Dec 03 12:00:32 2011 +0100
+++ b/QTfrontend/ui/page/AbstractPage.cpp	Sat Dec 03 14:36:36 2011 +0100
@@ -22,10 +22,14 @@
  */
 
 #include "AbstractPage.h"
+#include <QLabel>
+#include <QSize>
+#include <QFontMetricsF>
 
 AbstractPage::AbstractPage(QWidget* parent)
 {
     Q_UNUSED(parent);
+    defautDesc = new QString();
 
     font14 = new QFont("MS Shell Dlg", 14);
 }
@@ -45,12 +49,20 @@
     pageLayout->addWidget(btnBack, 1, 0, 1, 1, Qt::AlignLeft | Qt::AlignBottom);
 
     // add body layout as defined by the subclass
-    pageLayout->addLayout(bodyLayoutDefinition(), 0, 0, 1, 2);
+    pageLayout->addLayout(bodyLayoutDefinition(), 0, 0, 1, 3);
+
+    descLabel = new QLabel();
+    descLabel->setAlignment(Qt::AlignCenter);
+    descLabel->setWordWrap(true);
+    descLabel->setOpenExternalLinks(true);
+    descLabel->setFixedHeight(50);
+    descLabel->setStyleSheet("font-size: 16px");
+    pageLayout->addWidget(descLabel, 1, 1);
 
     // add footer layout
     QLayout * fld = footerLayoutDefinition();
     if (fld != NULL)
-        pageLayout->addLayout(fld, 1, 1);
+        pageLayout->addLayout(fld, 1, 2);
 
     // connect signals
     connect(btnBack, SIGNAL(clicked()), this, SIGNAL(goBack()));
@@ -97,3 +109,19 @@
 {
     btnBack->setVisible(visible);
 }
+
+void AbstractPage::setButtonDescription(QString desc)
+{
+    descLabel->setText(desc);
+}
+
+void AbstractPage::setDefautDescription(QString text)
+{
+    *defautDesc = text;
+    descLabel->setText(text);
+}
+
+QString * AbstractPage::getDefautDescription()
+{
+    return defautDesc;
+}
--- a/QTfrontend/ui/page/AbstractPage.h	Sat Dec 03 12:00:32 2011 +0100
+++ b/QTfrontend/ui/page/AbstractPage.h	Sat Dec 03 14:36:36 2011 +0100
@@ -56,6 +56,27 @@
 {
     Q_OBJECT
 
+    public:
+
+        /**
+        * @brief Changes the desc text (should not be called manualy)
+        *
+        * @param desc the description of the widget focused
+        */
+        void setButtonDescription(QString desc);
+
+        /**
+        * @brief Changes the desc defaut text
+        *
+        * @param text the defaut desc
+        */
+        void setDefautDescription(QString text);
+
+        /**
+        * @brief Get the desc defaut text
+        */
+        QString * getDefautDescription();
+
     signals:
         /**
          * @brief This signal is emitted when going back to the previous is
@@ -153,6 +174,9 @@
 
         QFont * font14; ///< used font
 
+        QLabel * descLabel; ///< text description
+        QString * defautDesc;
+
     private:
 
         QPushButton * btnBack; ///< back button
--- a/QTfrontend/ui/page/pagemain.cpp	Sat Dec 03 12:00:32 2011 +0100
+++ b/QTfrontend/ui/page/pagemain.cpp	Sat Dec 03 14:36:36 2011 +0100
@@ -91,10 +91,14 @@
 
     if(!isDevBuild)
     {
-        mainNote->setText(QLabel::tr("Tip: ") + randomTip());
+        //mainNote->setText(QLabel::tr("Tip: ") + randomTip());
+        setDefautDescription(QLabel::tr("Tip: ") + randomTip());
     }
     else
-        mainNote->setText(QLabel::tr("This development build is 'work in progress' and may not be compatible with other versions of the game. Some features might be broken or incomplete. Use at your own risk!"));
+    {
+        setDefautDescription(QLabel::tr("This development build is 'work in progress' and may not be compatible with other versions of the game. Some features might be broken or incomplete. Use at your own risk!"));
+        //mainNote->setText(QLabel::tr("This development build is 'work in progress' and may not be compatible with other versions of the game. Some features might be broken or incomplete. Use at your own risk!"));
+    }
 
 }
 
--- a/project_files/hedgewars.pro	Sat Dec 03 12:00:32 2011 +0100
+++ b/project_files/hedgewars.pro	Sat Dec 03 14:36:36 2011 +0100
@@ -95,7 +95,9 @@
     ../QTfrontend/ui_hwform.h \
 	../QTfrontend/KB.h \
     ../QTfrontend/hwconsts.h \
-    ../QTfrontend/sdlkeys.h
+    ../QTfrontend/sdlkeys.h \
+    ../QTfrontend/mouseoverfilter.h \
+    ../QTfrontend/ui/mouseoverfilter.h
 
 SOURCES += ../QTfrontend/model/ammoSchemeModel.cpp \
     ../QTfrontend/model/themesmodel.cpp \
@@ -169,7 +171,8 @@
     ../QTfrontend/util/SDLInteraction.cpp \
     ../QTfrontend/team.cpp \
     ../QTfrontend/ui_hwform.cpp \
-    ../QTfrontend/hwconsts.cpp
+    ../QTfrontend/hwconsts.cpp \
+    ../QTfrontend/ui/mouseoverfilter.cpp
 
 win32 {
 	SOURCES += ../QTfrontend/xfire.cpp