summaryrefslogtreecommitdiff
path: root/muse2/muse/app.cpp
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2011-08-30 16:25:38 +0000
committerFlorian Jung <flo@windfisch.org>2011-08-30 16:25:38 +0000
commit8c37b557d6f865b4320f7b1168030e7d54adacd0 (patch)
tree9c567b12dd852423df8056857417067151ff3f95 /muse2/muse/app.cpp
parent9cfbb1578284150b7251e6f58a77c4dc07667deb (diff)
added "arrange windows in rows" and "in columns" functions
Diffstat (limited to 'muse2/muse/app.cpp')
-rw-r--r--muse2/muse/app.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/muse2/muse/app.cpp b/muse2/muse/app.cpp
index cece85ed..91dbaed8 100644
--- a/muse2/muse/app.cpp
+++ b/muse2/muse/app.cpp
@@ -542,6 +542,8 @@ MusE::MusE(int argc, char** argv) : QMainWindow()
//-------- Windows Actions
windowsCascadeAction = new QAction(tr("Cascade"), this);
windowsTileAction = new QAction(tr("Tile"), this);
+ windowsRowsAction = new QAction(tr("In rows"), this);
+ windowsColumnsAction = new QAction(tr("In columns"), this);
//-------- Settings Actions
@@ -841,6 +843,8 @@ MusE::MusE(int argc, char** argv) : QMainWindow()
menuWindows->addAction(windowsCascadeAction);
menuWindows->addAction(windowsTileAction);
+ menuWindows->addAction(windowsRowsAction);
+ menuWindows->addAction(windowsColumnsAction);
//-------------------------------------------------------------
// popup Settings
@@ -896,6 +900,8 @@ MusE::MusE(int argc, char** argv) : QMainWindow()
mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setCentralWidget(mdiArea);
connect(windowsTileAction, SIGNAL(activated()), mdiArea, SLOT(tileSubWindows()));
+ connect(windowsRowsAction, SIGNAL(activated()), this, SLOT(arrangeSubWindowsRows()));
+ connect(windowsColumnsAction, SIGNAL(activated()), this, SLOT(arrangeSubWindowsColumns()));
connect(windowsCascadeAction, SIGNAL(activated()), mdiArea, SLOT(cascadeSubWindows()));
@@ -3202,6 +3208,8 @@ void MusE::updateWindowMenu()
menuWindows->addAction(windowsCascadeAction);
menuWindows->addAction(windowsTileAction);
+ menuWindows->addAction(windowsRowsAction);
+ menuWindows->addAction(windowsColumnsAction);
sep=false;
for (iToplevel it=toplevels.begin(); it!=toplevels.end(); it++)
@@ -3237,6 +3245,8 @@ void MusE::updateWindowMenu()
windowsCascadeAction->setEnabled(there_are_subwins);
windowsTileAction->setEnabled(there_are_subwins);
+ windowsRowsAction->setEnabled(there_are_subwins);
+ windowsColumnsAction->setEnabled(there_are_subwins);
}
void MusE::bringToFront(QWidget* widget)
@@ -3261,3 +3271,87 @@ void MusE::setFullscreen(bool val)
else
showNormal();
}
+
+
+
+list<QMdiSubWindow*> get_all_visible_subwins(QMdiArea* mdiarea)
+{
+ QList<QMdiSubWindow*> wins = mdiarea->subWindowList();
+ list<QMdiSubWindow*> result;
+
+ for (QList<QMdiSubWindow*>::iterator it=wins.begin(); it!=wins.end(); it++)
+ if ((*it)->isVisible() && ((*it)->isMinimized()==false))
+ result.push_back(*it);
+
+ return result;
+}
+
+void MusE::arrangeSubWindowsColumns()
+{
+ list<QMdiSubWindow*> wins=get_all_visible_subwins(mdiArea);
+ int n=wins.size();
+
+ if (n==0)
+ return;
+ else if (n==1)
+ (*wins.begin())->showMaximized();
+ else
+ {
+ int width = mdiArea->width();
+ int height = mdiArea->height();
+ int x_add = (*wins.begin())->frameGeometry().width() - (*wins.begin())->geometry().width();
+ int y_add = (*wins.begin())->frameGeometry().height() - (*wins.begin())->geometry().height();
+ int width_per_win = width/n;
+
+ if (x_add >= width_per_win)
+ {
+ printf("ERROR: tried to arrange subwins in columns, but there's too few space.\n");
+ return;
+ }
+
+ int i=0;
+ for (list<QMdiSubWindow*>::iterator it=wins.begin(); it!=wins.end(); it++, i++)
+ {
+ int left = (float) width*i/n;
+ int right = (float) width*(i+1.0)/n;
+
+ (*it)->move(left,0);
+ (*it)->resize(right-left-x_add, height-y_add);
+ }
+ }
+}
+
+void MusE::arrangeSubWindowsRows()
+{
+ list<QMdiSubWindow*> wins=get_all_visible_subwins(mdiArea);
+ int n=wins.size();
+
+ if (n==0)
+ return;
+ else if (n==1)
+ (*wins.begin())->showMaximized();
+ else
+ {
+ int width = mdiArea->width();
+ int height = mdiArea->height();
+ int x_add = (*wins.begin())->frameGeometry().width() - (*wins.begin())->geometry().width();
+ int y_add = (*wins.begin())->frameGeometry().height() - (*wins.begin())->geometry().height();
+ int height_per_win = height/n;
+
+ if (y_add >= height_per_win)
+ {
+ printf("ERROR: tried to arrange subwins in rows, but there's too few space.\n");
+ return;
+ }
+
+ int i=0;
+ for (list<QMdiSubWindow*>::iterator it=wins.begin(); it!=wins.end(); it++, i++)
+ {
+ int top = (float) height*i/n;
+ int bottom = (float) height*(i+1.0)/n;
+
+ (*it)->move(0,top);
+ (*it)->resize(width-x_add, bottom-top-y_add);
+ }
+ }
+}