From b067f303d8bde35f3e7f986f0ecdb9ffaf919a0b Mon Sep 17 00:00:00 2001 From: Dirk H Bartley Date: Sun, 25 Mar 2007 01:38:40 +0000 Subject: [PATCH] dhb I've got most of the user interface issues working as I was hoping to see them working. Now it is time to get another window into the stack and the tree. And also work on actual functionality. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4410 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/batstack.cpp | 23 +++++++- bacula/src/qt-console/batstack.h | 4 ++ bacula/src/qt-console/console/console.cpp | 12 ++--- bacula/src/qt-console/console/console.h | 1 - bacula/src/qt-console/joblist/joblist.h | 3 +- bacula/src/qt-console/mainwin.cpp | 65 +++++++++++++---------- bacula/src/qt-console/mainwin.h | 7 +-- 7 files changed, 73 insertions(+), 42 deletions(-) diff --git a/bacula/src/qt-console/batstack.cpp b/bacula/src/qt-console/batstack.cpp index 369f07e440..67ef83973f 100644 --- a/bacula/src/qt-console/batstack.cpp +++ b/bacula/src/qt-console/batstack.cpp @@ -48,7 +48,6 @@ void BatStack::AddTostack() void BatStack::RemoveFromstack() { /* Change from a stacked widget to a normal window */ - /* FIXME Will need to make it so that window cannot be closed */ m_parent->removeWidget(this); setWindowFlags(Qt::Window); showNormal(); @@ -65,6 +64,26 @@ void BatStack::Togglestack() } } -void BatStack::SetBSTreeWidgetItem(QTreeWidgetItem *treeItem){ +void BatStack::SetBSTreeWidgetItem(QTreeWidgetItem *treeItem) +{ m_treeItem=treeItem; } + +bool BatStack::isStacked() +{ + return m_stacked; +} + +void BatStack::closeEvent(QCloseEvent* event){ + /* Avoid a warning */ + event->type(); + /* A Widget was closed, lets toggle it back into the window, and set it in front. */ + AddTostack(); + /* FIXME Really having problems getting it to the front, toggles back into the stack fine though */ + /*int stackindex=m_parent->indexOf( this ); + if( stackindex >= 0 ){ + show(); + m_parent->setCurrentIndex(stackindex); + + }*/ +} diff --git a/bacula/src/qt-console/batstack.h b/bacula/src/qt-console/batstack.h index a21a04b87b..f724a80ef7 100644 --- a/bacula/src/qt-console/batstack.h +++ b/bacula/src/qt-console/batstack.h @@ -43,9 +43,13 @@ public: void RemoveFromstack(); void Togglestack(); void SetBSTreeWidgetItem(QTreeWidgetItem *treeItem); + bool isStacked(); QStackedWidget *m_parent; QTreeWidgetItem *m_treeItem; +public slots: + virtual void closeEvent(QCloseEvent* event); + private: bool m_stacked; }; diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index 6b05aab67b..e52f435366 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -115,7 +115,7 @@ void Console::connect() /* Update page selector to green to indicate that Console is connected */ mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/connected.png"))); QBrush greenBrush(Qt::green); - m_consoleItem->setForeground(0, greenBrush); + m_treeItem->setForeground(0, greenBrush); } jcr.dir_bsock = m_sock; @@ -379,7 +379,7 @@ void Console::write_dir(const char *msg) mainWin->set_status(" Director not connected. Click on connect button."); mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/disconnected.png"))); QBrush redBrush(Qt::red); - m_consoleItem->setForeground(0, redBrush); + m_treeItem->setForeground(0, redBrush); m_at_prompt = false; } } @@ -534,7 +534,7 @@ int Console::read() m_sock = NULL; mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/disconnected.png"))); QBrush redBrush(Qt::red); - m_consoleItem->setForeground(0, redBrush); + m_treeItem->setForeground(0, redBrush); m_notifier->setEnabled(false); delete m_notifier; m_notifier = NULL; @@ -574,9 +574,9 @@ void Console::notify(bool enable) m_notifier->setEnabled(enable); } -void Console::setTreeItem(QTreeWidgetItem *item) -{ - m_consoleItem = item; +void Console::setTreeItem(QTreeWidgetItem *item) +{ + m_treeItem = item; } void Console::setDirRes(DIRRES *dir) diff --git a/bacula/src/qt-console/console/console.h b/bacula/src/qt-console/console/console.h index a49ebcd82d..abe12a40d1 100644 --- a/bacula/src/qt-console/console/console.h +++ b/bacula/src/qt-console/console/console.h @@ -119,7 +119,6 @@ private: bool m_at_prompt; QSocketNotifier *m_notifier; QTextCursor *m_cursor; - QTreeWidgetItem *m_consoleItem; bool m_api_set; bool m_messages_pending; QTimer *m_timer; diff --git a/bacula/src/qt-console/joblist/joblist.h b/bacula/src/qt-console/joblist/joblist.h index 5ffff88289..c26399d95a 100644 --- a/bacula/src/qt-console/joblist/joblist.h +++ b/bacula/src/qt-console/joblist/joblist.h @@ -36,8 +36,9 @@ #include #include "ui_joblist.h" #include "console.h" +#include "batstack.h" -class JobList : public QWidget, public Ui::JobListForm +class JobList : public BatStack, public Ui::JobListForm { Q_OBJECT diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index fa81992be0..f76e03b9b2 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -76,14 +76,13 @@ void MainWin::createPages() m_console->setDirRes(dir); UnlockRes(); /* The top tree item representing the director */ - topItem = createTopPage(dir->name(), false); + topItem = createTopPage(dir->name()); topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png"))); /* Create Tree Widget Item */ - item = createPage("Console", topItem, true); + item = createPage("Console", topItem); + m_console->setTreeItem(item); /* Append to bstacklist */ m_bstacklist.append(m_console); - /* FIXME Associate tree item with console, may not be needed. */ - m_console->setTreeItem(item); /* Set BatStack m_treeItem */ m_console->SetBSTreeWidgetItem(item); QBrush redBrush(Qt::red); @@ -96,12 +95,12 @@ void MainWin::createPages() * 3. append to stacklist */ /* brestore */ - item = createPage("brestore", topItem, true); + item = createPage("brestore", topItem); m_brestore = new bRestore(stackedWidget,item); m_bstacklist.append(m_brestore); /* lastly for now, the medialist */ - item = createPage("Storage Tree", topItem, true); + item = createPage("Storage Tree", topItem ); m_medialist = new MediaList(stackedWidget, m_console, item); m_bstacklist.append(m_medialist); @@ -114,30 +113,19 @@ void MainWin::createPages() stackedWidget->setCurrentIndex(0); } -/* FIXME These Two are not needed any more because UserRole is not used. */ /* Create a root Tree Widget */ -QTreeWidgetItem *MainWin::createTopPage(char *name, bool canDisplay) +QTreeWidgetItem *MainWin::createTopPage(char *name ) { QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget); item->setText(0, name); - if (canDisplay) { - item->setData(0, Qt::UserRole, QVariant(m_pages++)); - } else { - item->setData(0, Qt::UserRole, QVariant(-1)); - } return item; } /* Create A Tree Widget Item which will be associated with a Page in the stacked widget */ -QTreeWidgetItem *MainWin::createPage(char *name, QTreeWidgetItem *parent, bool canDisplay) +QTreeWidgetItem *MainWin::createPage(char *name, QTreeWidgetItem *parent) { QTreeWidgetItem *item = new QTreeWidgetItem(parent); item->setText(0, name); - if (canDisplay) { - item->setData(0, Qt::UserRole, QVariant(m_pages++)); - } else { - item->setData(0, Qt::UserRole, QVariant(-1)); - } return item; } @@ -183,11 +171,11 @@ void MainWin::createConnections() connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line())); connect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about())); - connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this, - SLOT(treeItemClicked(QTreeWidgetItem *, int))); - connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, +/* connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this, SLOT(treeItemClicked(QTreeWidgetItem *, int))); connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this, + SLOT(treeItemClicked(QTreeWidgetItem *, int))); Commented out because it was getting to clicked multiple times*/ + connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(treeItemClicked(QTreeWidgetItem *, int))); connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(treeItemDoubleClicked(QTreeWidgetItem *, int))); @@ -236,13 +224,16 @@ void MainWin::treeItemClicked(QTreeWidgetItem *item, int column) { /* Iterate through and find the tree widget item clicked */ column+=0; - for ( QList::iterator bstackItem = m_bstacklist.begin(); bstackItem != m_bstacklist.end(); ++bstackItem ) { + QList::iterator bstackItem; + bstackItem = m_bstacklist.begin(); + while ( bstackItem != m_bstacklist.end() ){ if ( item == (*bstackItem)->m_treeItem ) { - int stackindex=stackedWidget->indexOf( *bstackItem ); - if( stackindex >= 0 ){ - stackedWidget->setCurrentIndex(stackindex); - } + int stackindex=stackedWidget->indexOf( *bstackItem ); + if( stackindex >= 0 ){ + stackedWidget->setCurrentIndex(stackindex); + } } + ++bstackItem; } } @@ -252,10 +243,21 @@ void MainWin::treeItemDoubleClicked(QTreeWidgetItem *item, int column) { /* Iterate through and find the tree widget item double clicked */ column+=0; - for ( QList::iterator bstackItem = m_bstacklist.begin(); bstackItem != m_bstacklist.end(); ++bstackItem ) { + QList::iterator bstackItem; + bstackItem = m_bstacklist.begin(); + while ( bstackItem != m_bstacklist.end() ){ if ( item == (*bstackItem)->m_treeItem ) { - (*bstackItem)->Togglestack(); + /* This could be a call a virtual function ?? or just popup a popup menu for an action */ + if ( (*bstackItem)->isStacked() == true ){ + m_bstackpophold=*bstackItem; + QMenu *popup = new QMenu( treeWidget ); + connect(popup->addAction("Pull Window Out"), SIGNAL(triggered()), this, SLOT(pullWindowOut())); + popup->exec(QCursor::pos()); + } else { + (*bstackItem)->Togglestack(); + } } + ++bstackItem; } } @@ -323,3 +325,8 @@ void MainWin::set_status(const char *buf) { statusBar()->showMessage(buf); } + +void MainWin::pullWindowOut() +{ + m_bstackpophold->Togglestack(); +} diff --git a/bacula/src/qt-console/mainwin.h b/bacula/src/qt-console/mainwin.h index 61082e5103..815f610eb4 100644 --- a/bacula/src/qt-console/mainwin.h +++ b/bacula/src/qt-console/mainwin.h @@ -69,6 +69,7 @@ public slots: void labelDialogClicked(); void runDialogClicked(); void restoreDialogClicked(); + void pullWindowOut(); protected: void closeEvent(QCloseEvent *event); @@ -77,15 +78,15 @@ protected: private: void createConnections(); void createPages(); - QTreeWidgetItem *createTopPage(char *name, bool canDisplay); - QTreeWidgetItem *createPage(char *name, QTreeWidgetItem *parent, bool canDisplay); + QTreeWidgetItem *createTopPage(char *name ); + QTreeWidgetItem *createPage(char *name, QTreeWidgetItem *parent ); private: QString m_UserInput; Console *m_console; bRestore *m_brestore; MediaList *m_medialist; - BatStack *m_bstack; + BatStack *m_bstackpophold; QList m_bstacklist; QStringList m_cmd_history; int m_cmd_last; -- 2.39.5