From: Dirk H Bartley Date: Sun, 8 Apr 2007 13:51:02 +0000 (+0000) Subject: dhb The changes in this commit are to make the right click in the page selector X-Git-Tag: Release-7.0.0~6605 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8133950205074b2265fffaffe8f83cab6b8fdec1;p=bacula%2Fbacula dhb The changes in this commit are to make the right click in the page selector more context sensitive. The intent is to have a menu popup describing the window that will be docked or undocked and whether it will be docked or undocked. This works by using treeItemChanged as a slot from the signal currentItemChanged from the treeWidget. After this, we now have the choice of removing the virtual functions in the pages class for click and double click. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4522 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/qt-console/main.ui b/bacula/src/qt-console/main.ui index 91a384d490..26e1518dbd 100644 --- a/bacula/src/qt-console/main.ui +++ b/bacula/src/qt-console/main.ui @@ -454,9 +454,12 @@ Undock Window - + + + images/unmark.png + - actionMediaPopUp + ToggleDock diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index c1c5658e57..51cf958ed2 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -45,7 +45,7 @@ MainWin::MainWin(QWidget *parent) : QMainWindow(parent) treeWidget->clear(); treeWidget->setColumnCount(1); treeWidget->setHeaderLabel("Select Page"); - treeWidget->addAction(actionUndock); +// treeWidget->addAction(actionUndock); treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu); m_pages = 0; @@ -79,6 +79,8 @@ void MainWin::createPages() /* The top tree item representing the director */ topItem = createTopPage(dir->name()); + topItem->setData(0, Qt::UserRole, QVariant(m_pages)); + m_pages++; topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png"))); /* Create Tree Widget Item */ @@ -86,7 +88,7 @@ void MainWin::createPages() m_console->SetPassedValues(stackedWidget, item, m_pages ); /* Append to pagelist */ - m_pagelist.insert(m_pages, m_console); + m_pagehash.insert(m_pages, m_console); /* Set Color of treeWidgetItem for the console * It will be set to gree in the console class if the connection is made. @@ -106,17 +108,17 @@ void MainWin::createPages() m_pages++; item=createPage("brestore", topItem); bRestore* brestore=new bRestore(stackedWidget, item, m_pages); - m_pagelist.insert(m_pages, brestore); + m_pagehash.insert(m_pages, brestore); /* lastly for now, the medialist */ m_pages++; item=createPage("Media", topItem ); MediaList* medialist=new MediaList(stackedWidget, m_console, item, m_pages); - m_pagelist.insert(m_pages, medialist); + m_pagehash.insert(m_pages, medialist); /* Iterate through and add to the stack */ - foreach (Pages *page, m_pagelist) + foreach (Pages *page, m_pagehash) page->dockPage(); treeWidget->expandItem(topItem); @@ -191,6 +193,9 @@ void MainWin::createConnections() SLOT(treeItemClicked(QTreeWidgetItem *, int))); connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(treeItemDoubleClicked(QTreeWidgetItem *, int))); + connect(treeWidget, SIGNAL( + currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), + this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *))); connect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows())); connect(actionConnect, SIGNAL(triggered()), m_console, SLOT(connect())); @@ -200,6 +205,7 @@ void MainWin::createConnections() connect(actionRun, SIGNAL(triggered()), this, SLOT(runDialogClicked())); connect(actionRestore, SIGNAL(triggered()), this, SLOT(restoreDialogClicked())); connect(actionUndock, SIGNAL(triggered()), this, SLOT(undockWindowButton())); + connect(actionToggleDock, SIGNAL(triggered()), this, SLOT(toggleDockContextWindow())); } /* @@ -241,38 +247,76 @@ void MainWin::treeItemClicked(QTreeWidgetItem *item, int column) { /* Use tree item's Qt::UserRole to get treeindex */ int treeindex = item->data(column, Qt::UserRole).toInt(); - int stackindex=stackedWidget->indexOf(m_pagelist.value(treeindex)); - if( stackindex >= 0 ){ - stackedWidget->setCurrentIndex(stackindex); + /* Is this one of the first level pages */ + if( m_pagehash.value(treeindex) ){ + Pages* page = m_pagehash.value(treeindex); + int stackindex=stackedWidget->indexOf(page); + + if( stackindex >= 0 ){ + stackedWidget->setCurrentIndex(0); + stackedWidget->setCurrentWidget(page); + } + /* run the virtual function in case this class overrides it */ + if( treeindex > 0 ){ + page->PgSeltreeWidgetClicked(); + } } - /* run the virtual function in case this class overrides it */ - m_pagelist.value(treeindex)->PgSeltreeWidgetClicked(); } /* * This subroutine is called with an item in the Page Selection window * is double clicked */ -void MainWin::treeItemDoubleClicked(QTreeWidgetItem *item, int column) +void MainWin::treeItemDoubleClicked(QTreeWidgetItem * /*item*/, int /*column*/) { - int treeindex = item->data(column, Qt::UserRole).toInt(); +} + +/* + * Called with a change of the highlighed tree widget item in the page selector. + */ + +void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *previousitem) +{ + int treeindex; + /* The Previous item */ + + /* Use tree item's Qt::UserRole to get treeindex now for the previousitem */ + if ( previousitem ){ + treeindex = previousitem->data(0, Qt::UserRole).toInt(); + /* Is this one of the first level pages */ + if( m_pagehash.value(treeindex) ){ + Pages* page = m_pagehash.value(treeindex); + treeWidget->removeAction(actionToggleDock); + foreach( QAction* pageaction, page->m_contextActions ){ + treeWidget->removeAction(pageaction); + } + } + } /* Use tree item's Qt::UserRole to get treeindex */ - if (m_pagelist.value(treeindex)->isDocked()) { - m_pagespophold = m_pagelist.value(treeindex); - - /* Create a popup menu before floating window */ - QMenu *popup = new QMenu( treeWidget ); - connect(popup->addAction("Undock Window"), SIGNAL(triggered()), this, - SLOT(undockWindow())); - popup->exec(QCursor::pos()); - } else { - /* Just pull it back in without prompting */ - m_pagelist.value(treeindex)->togglePageDocking(); + treeindex = currentitem->data(0, Qt::UserRole).toInt(); + + /* Is this one of the first level pages */ + if( m_pagehash.value(treeindex) ){ + Pages* page = m_pagehash.value(treeindex); + int stackindex = stackedWidget->indexOf(page); + + /* Is this page currently on the stack */ + if( stackindex >= 0 ){ + /* put this page on the top of the stack */ + stackedWidget->setCurrentIndex(stackindex); + } + /* run the virtual function in case this class overrides it */ + page->PgSeltreeWidgetCurrentItem(); + setContextMenuDockText(page, currentitem); + + treeWidget->addAction(actionToggleDock); + + /* Add the actions to the Page Selectors tree widget that are part of the + * current items list of desired actions regardless of whether on top of stack*/ + treeWidget->addActions(page->m_contextActions); } - /* Here is the virtual function so that different classes can do different things */ - m_pagelist.value(treeindex)->PgSeltreeWidgetDoubleClicked(); } void MainWin::labelDialogClicked() @@ -340,13 +384,72 @@ void MainWin::set_status(const char *buf) statusBar()->showMessage(buf); } -void MainWin::undockWindow() -{ - m_pagespophold->togglePageDocking(); -} - +/* + * Function to respond to the button bar button to undock + */ void MainWin::undockWindowButton() { Pages* page = (Pages*)stackedWidget->currentWidget(); page->togglePageDocking(); + /* The window has been undocked, lets change the context menu */ + setContextMenuDockText(); +} + +/* + * Function to respond to action on page selector context menu to toggle the + * dock status of the window associated with the page selectors current + * tree widget item. + */ +void MainWin::toggleDockContextWindow() +{ + QTreeWidgetItem *currentitem = treeWidget->currentItem(); + + /* Use tree item's Qt::UserRole to get treeindex */ + int treeindex = currentitem->data(0, Qt::UserRole).toInt(); + + /* Is this one of the first level pages */ + if( m_pagehash.value(treeindex) ){ + Pages* page = m_pagehash.value(treeindex); + page->togglePageDocking(); + /* Toggle the menu item. The window's dock status has been toggled */ + setContextMenuDockText(page, currentitem); + } +} + +/* + * Function to set the text of the toggle dock context menu when page and + * widget item are NOT known. This is an overoaded funciton. + * It is called from MainWin::undockWindowButton, it is not intended to change + * for the top pages tree widget, it is for the currently active tree widget + * item. Which is why the page is not passed. + */ +void MainWin::setContextMenuDockText() +{ + QTreeWidgetItem *currentitem = treeWidget->currentItem(); + + /* Use tree item's Qt::UserRole to get treeindex */ + int treeindex = currentitem->data(0, Qt::UserRole).toInt(); + + /* Is this one of the first level pages */ + if( m_pagehash.value(treeindex) ){ + Pages* page = m_pagehash.value(treeindex); + setContextMenuDockText(page, currentitem); + } +} + +/* + * Function to set the text of the toggle dock context menu when page and + * widget item are known. This is the more commonly used. + */ +void MainWin::setContextMenuDockText( Pages* page, QTreeWidgetItem* item ) +{ + QString docktext(""); + if( page->isDocked() ){ + docktext += "UnDock "; + } else { + docktext += "ReDock "; + } + docktext += item->text(0) += " Window"; + + actionToggleDock->setText(docktext); } diff --git a/bacula/src/qt-console/mainwin.h b/bacula/src/qt-console/mainwin.h index 10991f0211..a563e627dd 100644 --- a/bacula/src/qt-console/mainwin.h +++ b/bacula/src/qt-console/mainwin.h @@ -70,8 +70,11 @@ public slots: void labelDialogClicked(); void runDialogClicked(); void restoreDialogClicked(); - void undockWindow(); void undockWindowButton(); + void treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *); + void toggleDockContextWindow(); + void setContextMenuDockText(); + void setContextMenuDockText(Pages *, QTreeWidgetItem *); protected: void closeEvent(QCloseEvent *event); @@ -86,7 +89,7 @@ private: private: Console *m_console; Pages *m_pagespophold; - QHash m_pagelist; + QHash m_pagehash; QStringList m_cmd_history; int m_cmd_last; int m_pages; diff --git a/bacula/src/qt-console/medialist/medialist.cpp b/bacula/src/qt-console/medialist/medialist.cpp index 3489e8aa44..f21b68b074 100644 --- a/bacula/src/qt-console/medialist/medialist.cpp +++ b/bacula/src/qt-console/medialist/medialist.cpp @@ -211,6 +211,8 @@ void MediaList::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetI /* * Setup a context menu + * Made separate from populate so that it would not create context menu over and + * over as the tree is repopulated. */ void MediaList::createContextMenu() { @@ -224,4 +226,20 @@ void MediaList::createContextMenu() connect(mp_treeWidget, SIGNAL( currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *))); + /* connect to the action specific to this pages class */ + connect(actionRepopulateMediaTree, SIGNAL(triggered()), this, + SLOT(populateTree())); +} + +/* + * Virtual function which is called when this page is selected in the page selector tree + */ +void MediaList::PgSeltreeWidgetCurrentItem() +{ + if(!m_populated) { + populateTree(); + m_contextActions.append(actionRepopulateMediaTree); + createContextMenu(); + m_populated=true; + } } diff --git a/bacula/src/qt-console/medialist/medialist.h b/bacula/src/qt-console/medialist/medialist.h index 7d66bba80a..3ab3eb32f4 100644 --- a/bacula/src/qt-console/medialist/medialist.h +++ b/bacula/src/qt-console/medialist/medialist.h @@ -47,6 +47,7 @@ public: ~MediaList(); virtual void PgSeltreeWidgetClicked(); virtual void PgSeltreeWidgetDoubleClicked(); + virtual void PgSeltreeWidgetCurrentItem(); public slots: void treeItemClicked(QTreeWidgetItem *item, int column); @@ -55,9 +56,11 @@ public slots: void editMedia(); void showJobs(); +private slots: + void populateTree(); + private: void createConnections(); - void populateTree(); void createContextMenu(); private: diff --git a/bacula/src/qt-console/medialist/medialist.ui b/bacula/src/qt-console/medialist/medialist.ui index a60e2dd76a..f56ce7a960 100644 --- a/bacula/src/qt-console/medialist/medialist.ui +++ b/bacula/src/qt-console/medialist/medialist.ui @@ -23,6 +23,14 @@ + + + ../images/run.png + + + Repopulate Media Tree + + diff --git a/bacula/src/qt-console/pages.cpp b/bacula/src/qt-console/pages.cpp index ccccd12153..fb262a8b5b 100644 --- a/bacula/src/qt-console/pages.cpp +++ b/bacula/src/qt-console/pages.cpp @@ -113,10 +113,19 @@ void Pages::closeEvent(QCloseEvent* /*event*/) /* FIXME Really having problems getting it to the front, toggles back into the stack fine though */ int stackindex=m_parent->indexOf( this ); +printf("In Pages closeEvent a\n"); if( stackindex >= 0 ){ +printf("In Pages closeEvent b\n"); + m_parent->setCurrentIndex(0); + //m_parent->setCurrentIndex(stackindex); + m_parent->setCurrentWidget(this); + m_parent->update(); + update(); + setUpdatesEnabled(true); + m_parent->show(); show(); - m_parent->setCurrentIndex(stackindex); - + m_parent->repaint(); + repaint(); } #endif } @@ -134,6 +143,10 @@ void Pages::PgSeltreeWidgetDoubleClicked() { } +void Pages::PgSeltreeWidgetCurrentItem() +{ +} + /* * This function exists because I wanted to have an easy way for new programmers to understand * exactly what values needed to be set in order to behave correctly in the interface. It can diff --git a/bacula/src/qt-console/pages.h b/bacula/src/qt-console/pages.h index 48d9a18fc0..5840ce0929 100644 --- a/bacula/src/qt-console/pages.h +++ b/bacula/src/qt-console/pages.h @@ -59,9 +59,11 @@ public: bool isDocked(); QStackedWidget *m_parent; QTreeWidgetItem *m_treeItem; + QList m_contextActions; void SetPassedValues(QStackedWidget*, QTreeWidgetItem*, int ); virtual void PgSeltreeWidgetClicked(); virtual void PgSeltreeWidgetDoubleClicked(); + virtual void PgSeltreeWidgetCurrentItem(); public slots: /* closeEvent is a virtual function inherited from QWidget */