Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed - actions for floating widgets would have to much visual impact…

…, turned them into a menu
  • Loading branch information...
commit 2cb2222d8d4e7209e9daab8cf06243753a8e41af 1 parent 64edd2a
Pierre Marchand authored
View
92 src/floatingwidgettoolbar.cpp
@@ -23,63 +23,79 @@
#include "floatingwidget.h"
+#include <QMenu>
+#include <QAction>
+
FloatingWidgetToolBar::FloatingWidgetToolBar(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::FloatingWidgetToolBar),
- noClose(false)
+ QWidget(parent),
+ ui(new Ui::FloatingWidgetToolBar),
+ noClose(false),
+ isDetached(false)
{
- ui->setupUi(this);
- ui->closeButton->hide();
- ui->hideButton->hide();
- connect(ui->closeButton, SIGNAL(clicked()), this, SIGNAL(Close()));
- connect(ui->hideButton, SIGNAL(clicked()), this, SIGNAL(Hide()));
- connect(ui->printButton, SIGNAL(clicked()), this, SIGNAL(Print()));
- connect(ui->detachButton, SIGNAL(clicked()), this, SLOT(setDetached()));
+ ui->setupUi(this);
+
+ menu = new QMenu(this);
+ setupMenu();
+ ui->toolButton->setMenu(menu);
+
}
FloatingWidgetToolBar::~FloatingWidgetToolBar()
{
- delete ui;
+ delete ui;
}
void FloatingWidgetToolBar::changeEvent(QEvent *e)
{
- QWidget::changeEvent(e);
- switch (e->type()) {
- case QEvent::LanguageChange:
- ui->retranslateUi(this);
- break;
- default:
- break;
- }
+ QWidget::changeEvent(e);
+ switch (e->type()) {
+ case QEvent::LanguageChange:
+ ui->retranslateUi(this);
+ break;
+ default:
+ break;
+ }
}
-void FloatingWidgetToolBar::setDetached()
+
+void FloatingWidgetToolBar::setupMenu()
{
- ui->closeButton->show();
- ui->hideButton->show();
- ui->detachButton->hide();
+ menu->clear();
-// QWidget *p(parent());
-// while(0 != p)
-// {
-// if(QString(p->metaObject()->className()) == QString("FloatingWidget"))
-// {
-// FloatingWidget * fw(reinterpret_cast<FloatingWidget*>(p));
-// fw->ddetach();
-// break;
-// }
-// p = parent();
-// }
+ if(isDetached)
+ {
+ if(!noClose)
+ {
+ closeAction = new QAction(tr("Close"), menu);
+ menu->addAction(closeAction);
+ connect(closeAction, SIGNAL(triggered()), this, SIGNAL(Close()));
+ }
+ hideAction = new QAction(tr("Hide"), menu);
+ menu->addAction(hideAction);
+ connect(hideAction, SIGNAL(triggered()), this, SIGNAL(Hide()));
+ }
+ printAction = new QAction(tr("Print"), menu);
+ menu->addAction(printAction);
+ connect(printAction, SIGNAL(triggered()), this, SIGNAL(Print()));
+ if(!isDetached)
+ {
+ detachAction = new QAction(tr("Detach"), menu);
+ menu->addAction(detachAction);
+ connect(detachAction, SIGNAL(triggered()), this, SLOT(setDetached()));
+ }
+
+}
+
+void FloatingWidgetToolBar::setDetached()
+{
+ isDetached = true;
+ setupMenu();
emit Detach();
}
void FloatingWidgetToolBar::setNoClose(bool c)
{
noClose = c;
- if(noClose)
- ui->closeButton->hide();
- else
- ui->closeButton->show();
+ setupMenu();
}
View
12 src/floatingwidgettoolbar.h
@@ -23,6 +23,9 @@
#include <QWidget>
+class QMenu;
+class QAction;
+
namespace Ui {
class FloatingWidgetToolBar;
}
@@ -43,7 +46,16 @@ class FloatingWidgetToolBar : public QWidget
private:
Ui::FloatingWidgetToolBar *ui;
+ QAction * closeAction;
+ QAction * hideAction;
+ QAction * printAction;
+ QAction * detachAction;
+
+ QMenu * menu;
bool noClose;
+ bool isDetached;
+
+ void setupMenu();
public slots:
void setDetached();
View
128 src/floatingwidgettoolbar.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>544</width>
- <height>35</height>
+ <height>20</height>
</rect>
</property>
<property name="windowTitle">
@@ -19,80 +19,76 @@
</property>
<item row="0" column="0">
<widget class="QFrame" name="frame">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>20</height>
+ </size>
+ </property>
<property name="frameShape">
- <enum>QFrame::StyledPanel</enum>
+ <enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
+ <property name="midLineWidth">
+ <number>0</number>
+ </property>
<layout class="QGridLayout" name="gridLayout">
- <property name="margin">
+ <property name="leftMargin">
+ <number>4</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>4</number>
+ </property>
+ <property name="bottomMargin">
<number>2</number>
</property>
<item row="0" column="0">
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QPushButton" name="closeButton">
- <property name="font">
- <font>
- <pointsize>8</pointsize>
- </font>
- </property>
- <property name="text">
- <string>Close</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="hideButton">
- <property name="font">
- <font>
- <pointsize>8</pointsize>
- </font>
- </property>
- <property name="text">
- <string>Hide</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="detachButton">
- <property name="font">
- <font>
- <pointsize>8</pointsize>
- </font>
- </property>
- <property name="text">
- <string>Detach</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>10</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="printButton">
- <property name="font">
- <font>
- <pointsize>8</pointsize>
- </font>
- </property>
- <property name="text">
- <string>Print</string>
- </property>
- </widget>
- </item>
- </layout>
+ <widget class="QToolButton" name="toolButton">
+ <property name="font">
+ <font>
+ <pointsize>8</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string>Actions</string>
+ </property>
+ <property name="popupMode">
+ <enum>QToolButton::InstantPopup</enum>
+ </property>
+ <property name="toolButtonStyle">
+ <enum>Qt::ToolButtonIconOnly</enum>
+ </property>
+ <property name="autoRaise">
+ <bool>true</bool>
+ </property>
+ <property name="arrowType">
+ <enum>Qt::NoArrow</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
</item>
</layout>
</widget>
Please sign in to comment.
Something went wrong with that request. Please try again.