Author: mir3x
Date: Mon Dec 14 03:07:53 2015
New Revision: 30995

URL: http://svn.gna.org/viewcvs/freeciv?rev=30995&view=rev
Log:
Added closing chat and messages with right click on their label, 
and restoring them with left click when both are hidden. 

See patch #6671


Modified:
    branches/S2_6/client/gui-qt/messagewin.cpp
    branches/S2_6/client/gui-qt/messagewin.h

Modified: branches/S2_6/client/gui-qt/messagewin.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/messagewin.cpp?rev=30995&r1=30994&r2=30995&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/messagewin.cpp  (original)
+++ branches/S2_6/client/gui-qt/messagewin.cpp  Mon Dec 14 03:07:53 2015
@@ -25,6 +25,26 @@
 #include "messagewin.h"
 #include "qtg_cxxside.h"
 #include "sprite.h"
+
+/***************************************************************************
+  Constructor for right_click_button
+***************************************************************************/
+right_click_button::right_click_button(QWidget *parent) :
+    QPushButton(parent)
+{
+}
+
+/***************************************************************************
+  Mouse event for right_clik_button
+***************************************************************************/
+void right_click_button::mousePressEvent(QMouseEvent *e)
+{
+  if (e->button() == Qt::RightButton) {
+    emit right_clicked();
+  } else if (e->button() == Qt::LeftButton) {
+    emit clicked();
+  }
+}
 
 /***************************************************************************
   info_tab constructor
@@ -40,9 +60,9 @@
     "QPushButton {border: noborder;}");
 
   layout = new QGridLayout;
-  msg_button = new QPushButton;
+  msg_button = new right_click_button;
   msg_button->setText(_("Messages"));
-  chat_button = new QPushButton;
+  chat_button = new right_click_button;
   chat_button->setText(_("Chat"));
   hide_button = new QPushButton(
                   style()->standardIcon(QStyle::SP_TitleBarMinButton), "");
@@ -69,11 +89,32 @@
   connect(hide_button, SIGNAL(clicked()), SLOT(hide_me()));
   connect(msg_button, SIGNAL(clicked()), SLOT(activate_msg()));
   connect(chat_button, SIGNAL(clicked()), SLOT(activate_chat()));
+  connect(msg_button, SIGNAL(right_clicked()), SLOT(on_right_clicked()));
+  connect(chat_button, SIGNAL(right_clicked()), SLOT(on_right_clicked()));
   resx = false;
   resy = false;
   chat_stretch = 5;
   msg_stretch = 5;
   setMouseTracking(true);
+}
+
+/***************************************************************************
+  Slot for receinving right clicks, hides messages or chat
+***************************************************************************/
+void info_tab::on_right_clicked()
+{
+  right_click_button *rcb;
+  rcb = qobject_cast<right_click_button *>(sender());
+  if (rcb == chat_button && !hidden_mess) {
+    hide_chat(true);
+  } else if (rcb == chat_button && hidden_mess) {
+    hide_me();
+  }
+  if (rcb == msg_button && !hidden_chat) {
+    hide_messages(true);
+  } else if (rcb == msg_button && hidden_chat) {
+    hide_me();
+  }
 }
 
 /***************************************************************************
@@ -180,7 +221,13 @@
 {
   int i;
 
-  if (hidden_mess){
+  if (hidden_state) {
+    hidden_mess = true;
+    hidden_chat = false;
+    hide_me();
+    return;
+  }
+  if (hidden_mess) {
     return;
   }
   i = layout->columnStretch(6);
@@ -249,6 +296,13 @@
 void info_tab::activate_msg()
 {
   int i;
+
+  if (hidden_state) {
+    hidden_chat = true;
+    hidden_mess = false;
+    hide_me();
+    return;
+  }
   if (hidden_chat) {
     return;
   }
@@ -276,14 +330,14 @@
 ***************************************************************************/
 void info_tab::hide_me()
 {
+  whats_hidden = 0;
+  if (hidden_mess && !hidden_chat) {
+    whats_hidden = 1;
+  }
+  if (hidden_chat && !hidden_mess) {
+    whats_hidden = 2;
+  }
   if (!hidden_state) {
-    whats_hidden = 0;
-    if (hidden_mess && !hidden_chat) {
-      whats_hidden = 1;
-    }
-    if (hidden_chat && !hidden_mess) {
-      whats_hidden = 2;
-    }
     hide_messages(true);
     hide_chat(true);
     last_size.setWidth(width());
@@ -320,6 +374,10 @@
       hide_chat(true);
       break;
     }
+  }
+  if (hidden_state) {
+    chat_button->show();
+    msg_button->show();
   }
 }
 

Modified: branches/S2_6/client/gui-qt/messagewin.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/messagewin.h?rev=30995&r1=30994&r2=30995&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/messagewin.h    (original)
+++ branches/S2_6/client/gui-qt/messagewin.h    Mon Dec 14 03:07:53 2015
@@ -30,6 +30,21 @@
 //qt-client
 #include "chatline.h"
 #include "mapview.h"
+
+
+/***************************************************************************
+  QPushButton receiving right click event
+***************************************************************************/
+class right_click_button : public QPushButton
+{
+  Q_OBJECT
+public:
+  explicit right_click_button(QWidget *parent = 0);
+signals:
+  void right_clicked();
+protected:
+  void mousePressEvent(QMouseEvent *e);
+};
 
 /***************************************************************************
   Class representing message output
@@ -74,9 +89,9 @@
   void change_layout();
   void update_menu();
   QPoint cursor;
-  QPushButton *chat_button;
+  right_click_button *chat_button;
   QPushButton *hide_button;
-  QPushButton *msg_button;
+  right_click_button *msg_button;
   QSize last_size;
   bool hidden_state;
   bool layout_changed;
@@ -90,6 +105,7 @@
 private slots:
   void activate_msg();
   void activate_chat();
+  void on_right_clicked();
 protected:
   void paint(QPainter *painter, QPaintEvent *event);
   void paintEvent(QPaintEvent *event);


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to