diff options
Diffstat (limited to 'libLumina')
-rw-r--r-- | libLumina/LuminaUtils.cpp | 84 | ||||
-rw-r--r-- | libLumina/LuminaUtils.h | 36 | ||||
-rw-r--r-- | libLumina/LuminaXDG.cpp | 1 |
3 files changed, 121 insertions, 0 deletions
diff --git a/libLumina/LuminaUtils.cpp b/libLumina/LuminaUtils.cpp index 5f2de8b3..699f55fc 100644 --- a/libLumina/LuminaUtils.cpp +++ b/libLumina/LuminaUtils.cpp @@ -718,3 +718,87 @@ void LUtils::LoadSystemDefaults(bool skipOS){ LUtils::writeFile(setdir+"/desktopsettings.conf", deskset, true); LUtils::writeFile(setdir+"/lumina-open.conf", lopenset, true); } + +// ======================= +// RESIZEMENU CLASS +// ======================= +ResizeMenu::ResizeMenu(QWidget *parent) : QMenu(parent){ + this->setContentsMargins(1,1,1,1); + resizeSide = NONE; + cAct = new QWidgetAction(this); + contents = 0; + connect(this, SIGNAL(aboutToShow()), this, SLOT(clearFlags()) ); + connect(this, SIGNAL(aboutToHide()), 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 + switch(resizeSide){ + case TOP: + geom.setTop(ev->pos().y()); + if(contents!=0){ contents->setFixedSize(geom.size()); } + break; + case BOTTOM: + geom.setBottom(ev->pos().y()); + this->setGeometry(geom); + if(contents!=0){ contents->setFixedSize(geom.size()); } + break; + case LEFT: + geom.setLeft(ev->pos().x()); + this->setGeometry(geom); + if(contents!=0){ contents->setFixedSize(geom.size()); } + break; + case RIGHT: + geom.setRight(ev->pos().x()); + this->setGeometry(geom); + if(contents!=0){ contents->setFixedSize(geom.size()); } + break; + default: //NONE + qDebug() << " - Mouse At:" << ev->pos(); + //Just adjust the mouse cursor which is shown + if(ev->pos().x()==0){ this->setCursor(Qt::SizeHorCursor); } + else if(ev->pos().x() == this->width()){ this->setCursor(Qt::SizeHorCursor); } + else if(ev->pos().y()==0){ this->setCursor(Qt::SizeVerCursor); } + else if(ev->pos().y() == this->height()){ this->setCursor(Qt::SizeVerCursor); } + else{ this->setCursor(Qt::ArrowCursor); } + } + QWidget::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(); } + else{ QWidget::mousePressEvent(ev); } //do normal processing +} + +void ResizeMenu::mouseReleaseEvent(QMouseEvent *ev){ + if(ev->button() == Qt::LeftButton && resizeSide!=NONE ){ + //qDebug() << "Mouse Release Event:" << ev->pos() << resizeSide; + resizeSide = NONE; + emit MenuResized(this->size()); + ev->accept(); + }else{ + QWidget::mouseReleaseEvent(ev); //do normal processing + } +}
\ No newline at end of file diff --git a/libLumina/LuminaUtils.h b/libLumina/LuminaUtils.h index 3ab741a0..bbb40c38 100644 --- a/libLumina/LuminaUtils.h +++ b/libLumina/LuminaUtils.h @@ -19,6 +19,10 @@ #include <QObject> #include <QTranslator> #include <QApplication> +#include <QMenu> +#include <QMouseEvent> +#include <QSize> +#include <QWidgetAction> class LUtils{ public: @@ -87,4 +91,36 @@ 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{ + 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/libLumina/LuminaXDG.cpp b/libLumina/LuminaXDG.cpp index 15cd47fe..3fe533a5 100644 --- a/libLumina/LuminaXDG.cpp +++ b/libLumina/LuminaXDG.cpp @@ -421,6 +421,7 @@ QStringList LXDG::systemApplicationDirs(){ //for(int s=0; s<subs.length(); s++){ out << dir.absoluteFilePath(subs[s]); } } } + //qDebug() << "System Application Dirs:" << out; return out; } |