aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Moore <ken@ixsystems.com>2016-11-03 13:55:36 -0400
committerKen Moore <ken@ixsystems.com>2016-11-03 13:55:36 -0400
commit43358bcfd3f815d6f124c70d330a3128aeff9c08 (patch)
tree8ec9a3bdb5093754ce5c04b7062abd02788f17c7
parentAdd the new Qt5 theme engine setting to lumina-config. (diff)
downloadlumina-43358bcfd3f815d6f124c70d330a3128aeff9c08.tar.gz
lumina-43358bcfd3f815d6f124c70d330a3128aeff9c08.tar.bz2
lumina-43358bcfd3f815d6f124c70d330a3128aeff9c08.zip
Convert the ResizeMenu class into it's own files:
1) Add a new .pri for loading just that class (works stand-alone) 2) Setup the lumina-desktop to use the new build framework for including that class.
-rw-r--r--src-qt5/core/libLumina/LuminaUtils.cpp4
-rw-r--r--src-qt5/core/libLumina/LuminaUtils.h4
-rw-r--r--src-qt5/core/libLumina/ResizeMenu.cpp106
-rw-r--r--src-qt5/core/libLumina/ResizeMenu.h51
-rw-r--r--src-qt5/core/libLumina/ResizeMenu.pri6
-rw-r--r--src-qt5/core/lumina-desktop/lumina-desktop.pro3
-rw-r--r--src-qt5/core/lumina-desktop/panel-plugins/systemstart/LStartButton.h1
7 files changed, 171 insertions, 4 deletions
diff --git a/src-qt5/core/libLumina/LuminaUtils.cpp b/src-qt5/core/libLumina/LuminaUtils.cpp
index 0fb44ff1..0d808d1d 100644
--- a/src-qt5/core/libLumina/LuminaUtils.cpp
+++ b/src-qt5/core/libLumina/LuminaUtils.cpp
@@ -966,7 +966,7 @@ int LUtils::VersionStringToNumber(QString version){
// =======================
// RESIZEMENU CLASS
// =======================
-ResizeMenu::ResizeMenu(QWidget *parent) : QMenu(parent){
+/*ResizeMenu::ResizeMenu(QWidget *parent) : QMenu(parent){
this->setContentsMargins(1,1,1,1);
this->setMouseTracking(true);
resizeSide = NONE;
@@ -1060,4 +1060,4 @@ void ResizeMenu::mouseReleaseEvent(QMouseEvent *ev){
}else{
QMenu::mouseReleaseEvent(ev); //do normal processing
}
-}
+}*/
diff --git a/src-qt5/core/libLumina/LuminaUtils.h b/src-qt5/core/libLumina/LuminaUtils.h
index e07363ca..4a0a19af 100644
--- a/src-qt5/core/libLumina/LuminaUtils.h
+++ b/src-qt5/core/libLumina/LuminaUtils.h
@@ -99,7 +99,7 @@ public:
//Special subclass for a menu which the user can grab the edges and resize as necessary
// Note: Make sure that you don't set 0pixel contents margins on this menu
// - it needs at least 1 pixel margins for the user to be able to grab it
-class ResizeMenu : public QMenu{
+/*class ResizeMenu : public QMenu{
Q_OBJECT
public:
ResizeMenu(QWidget *parent = 0);
@@ -126,6 +126,6 @@ protected:
signals:
void MenuResized(QSize); //Emitted when the menu is manually resized by the user
-};
+};*/
#endif
diff --git a/src-qt5/core/libLumina/ResizeMenu.cpp b/src-qt5/core/libLumina/ResizeMenu.cpp
new file mode 100644
index 00000000..9f291134
--- /dev/null
+++ b/src-qt5/core/libLumina/ResizeMenu.cpp
@@ -0,0 +1,106 @@
+//===========================================
+// Lumina-DE source code
+// Copyright (c) 2013-2016, Ken Moore
+// Available under the 3-clause BSD license
+// See the LICENSE file for full details
+//===========================================
+#include "ResizeMenu.h"
+
+// =======================
+// RESIZEMENU CLASS
+// =======================
+ResizeMenu::ResizeMenu(QWidget *parent) : QMenu(parent){
+ this->setContentsMargins(1,1,1,1);
+ this->setMouseTracking(true);
+ resizeSide = NONE;
+ cAct = new QWidgetAction(this);
+ contents = 0;
+ connect(this, SIGNAL(aboutToShow()), this, SLOT(clearFlags()) );
+ connect(this, SIGNAL(aboutToHide()), this, SLOT(clearFlags()) );
+ connect(cAct, SIGNAL(hovered()), this, SLOT(clearFlags()) );
+}
+
+ResizeMenu::~ResizeMenu(){
+
+}
+
+void ResizeMenu::setContents(QWidget *con){
+ this->clear();
+ cAct->setDefaultWidget(con);
+ this->addAction(cAct);
+ contents = con; //save for later
+ contents->setCursor(Qt::ArrowCursor);
+}
+
+void ResizeMenu::mouseMoveEvent(QMouseEvent *ev){
+ QRect geom = this->geometry();
+ //Note: The exact position does not matter as much as the size
+ // since the window will be moved again the next time it is shown
+ // The "-2" in the sizing below accounts for the menu margins
+ QPoint gpos = this->mapToGlobal(ev->pos());
+ bool handled = false;
+ switch(resizeSide){
+ case TOP:
+ if(gpos.y() >= geom.bottom()-1){ break; }
+ geom.setTop(gpos.y());
+ this->setGeometry(geom);
+ if(contents!=0){ contents->setFixedSize(QSize(geom.width()-2, geom.height()-2));}
+ handled = true;
+ break;
+ case BOTTOM:
+ if(gpos.y() <= geom.top()+1){ break; }
+ geom.setBottom( gpos.y());
+ this->setGeometry(geom);
+ if(contents!=0){ contents->setFixedSize(QSize(geom.width()-2, geom.height()-2));}
+ handled = true;
+ break;
+ case LEFT:
+ if(gpos.x() >= geom.right()-1){ break; }
+ geom.setLeft(gpos.x());
+ this->setGeometry(geom);
+ if(contents!=0){ contents->setFixedSize(QSize(geom.width()-2, geom.height()-2));}
+ handled = true;
+ break;
+ case RIGHT:
+ if(gpos.x() <= geom.left()+1){ break; }
+ geom.setRight(gpos.x());
+ this->setGeometry(geom);
+ if(contents!=0){ contents->setFixedSize(QSize(geom.width()-2, geom.height()-2));}
+ handled = true;
+ break;
+ default: //NONE
+ //qDebug() << " - Mouse At:" << ev->pos();
+ //Just adjust the mouse cursor which is shown
+ if(ev->pos().x()<=1 && ev->pos().x() >= -1){ this->setCursor(Qt::SizeHorCursor); }
+ else if(ev->pos().x() >= this->width()-1 && ev->pos().x() <= this->width()+1){ this->setCursor(Qt::SizeHorCursor); }
+ else if(ev->pos().y()<=1 && ev->pos().y() >= -1){ this->setCursor(Qt::SizeVerCursor); }
+ else if(ev->pos().y() >= this->height()-1 && ev->pos().y() <= this->height()+1){ this->setCursor(Qt::SizeVerCursor); }
+ else{ this->setCursor(Qt::ArrowCursor); }
+ }
+ if(!handled){ QMenu::mouseMoveEvent(ev); } //do normal processing as well
+}
+
+void ResizeMenu::mousePressEvent(QMouseEvent *ev){
+ bool used = false;
+ if(ev->buttons().testFlag(Qt::LeftButton) && resizeSide==NONE){
+ //qDebug() << "Mouse Press Event:" << ev->pos() << resizeSide;
+ if(ev->pos().x()<=1 && ev->pos().x() >= -1){resizeSide = LEFT; used = true;}
+ else if(ev->pos().x() >= this->width()-1 && ev->pos().x() <= this->width()+1){ resizeSide = RIGHT; used = true;}
+ else if(ev->pos().y()<=1 && ev->pos().y() >= -1){ resizeSide = TOP; used = true; }
+ else if(ev->pos().y() >= this->height()-1 && ev->pos().y() <= this->height()+1){ resizeSide = BOTTOM; used = true; }
+ }
+ if(used){ ev->accept(); this->grabMouse(); }
+ else{ QMenu::mousePressEvent(ev); } //do normal processing
+}
+
+void ResizeMenu::mouseReleaseEvent(QMouseEvent *ev){
+ this->releaseMouse();
+ if(ev->button() == Qt::LeftButton && resizeSide!=NONE ){
+ //qDebug() << "Mouse Release Event:" << ev->pos() << resizeSide;
+ resizeSide = NONE;
+ emit MenuResized(contents->size());
+ ev->accept();
+ }else{
+ QMenu::mouseReleaseEvent(ev); //do normal processing
+ }
+}
diff --git a/src-qt5/core/libLumina/ResizeMenu.h b/src-qt5/core/libLumina/ResizeMenu.h
new file mode 100644
index 00000000..ed909da3
--- /dev/null
+++ b/src-qt5/core/libLumina/ResizeMenu.h
@@ -0,0 +1,51 @@
+//===========================================
+// Lumina-DE source code
+// Copyright (c) 2012-2016, Ken Moore
+// Available under the 3-clause BSD license
+// See the LICENSE file for full details
+//===========================================
+#ifndef _LUMINA_LIBRARY_RESIZE_MENU_H
+#define _LUMINA_LIBRARY_RESIZE_MENU_H
+
+#include <QMenu>
+#include <QWidget>
+#include <QMouseEvent>
+#include <QAction>
+#include <QWidgetAction>
+#include <QRect>
+#include <QCursor>
+#include <QPoint>
+
+//Special subclass for a menu which the user can grab the edges and resize as necessary
+// Note: Make sure that you don't set 0pixel contents margins on this menu
+// - it needs at least 1 pixel margins for the user to be able to grab it
+class ResizeMenu : public QMenu{
+ Q_OBJECT
+public:
+ ResizeMenu(QWidget *parent = 0);
+ virtual ~ResizeMenu();
+
+ void setContents(QWidget *con);
+
+private:
+ enum SideFlag{NONE, TOP, BOTTOM, LEFT, RIGHT};
+ SideFlag resizeSide;
+ QWidget *contents;
+ QWidgetAction *cAct;
+
+private slots:
+ void clearFlags(){
+ resizeSide=NONE;
+ }
+
+protected:
+ virtual void mouseMoveEvent(QMouseEvent *ev);
+ virtual void mousePressEvent(QMouseEvent *ev);
+ virtual void mouseReleaseEvent(QMouseEvent *ev);
+
+signals:
+ void MenuResized(QSize); //Emitted when the menu is manually resized by the user
+
+};
+
+#endif
diff --git a/src-qt5/core/libLumina/ResizeMenu.pri b/src-qt5/core/libLumina/ResizeMenu.pri
new file mode 100644
index 00000000..2b055841
--- /dev/null
+++ b/src-qt5/core/libLumina/ResizeMenu.pri
@@ -0,0 +1,6 @@
+#Subproject file for bundling the ResizeMenu class into an application
+SOURCES += $${PWD}/ResizeMenu.cpp
+HEADERS += $${PWD}/ResizeMenu.h
+#Add this dir to the include path
+# This allows the application to simply use "#include <ResizeMenu.h>" to use it
+INCLUDEPATH *= $${PWD}
diff --git a/src-qt5/core/lumina-desktop/lumina-desktop.pro b/src-qt5/core/lumina-desktop/lumina-desktop.pro
index 814725cc..effa0508 100644
--- a/src-qt5/core/lumina-desktop/lumina-desktop.pro
+++ b/src-qt5/core/lumina-desktop/lumina-desktop.pro
@@ -53,6 +53,9 @@ HEADERS += Globals.h \
FORMS += SystemWindow.ui \
BootSplash.ui
+#include all the special classes from the Lumina tree
+include(../libLumina/ResizeMenu.pri)
+
#Now include all the files for the various plugins
include(panel-plugins/panel-plugins.pri)
include(desktop-plugins/desktop-plugins.pri)
diff --git a/src-qt5/core/lumina-desktop/panel-plugins/systemstart/LStartButton.h b/src-qt5/core/lumina-desktop/panel-plugins/systemstart/LStartButton.h
index 1a17b75b..22742bc5 100644
--- a/src-qt5/core/lumina-desktop/panel-plugins/systemstart/LStartButton.h
+++ b/src-qt5/core/lumina-desktop/panel-plugins/systemstart/LStartButton.h
@@ -25,6 +25,7 @@
// libLumina includes
#include <LuminaXDG.h>
#include <LuminaUtils.h>
+#include <ResizeMenu.h>
#include "StartMenu.h"
bgstack15