From 4fdb45edfffa8d71a8de6e236cb2371a8d73d31d Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 27 Jan 2007 17:00:19 +0000 Subject: [PATCH] Add tree selection of stacked widgets git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4058 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/mainwindow.cpp | 44 +++++++++++++++++++++++++++- bacula/src/qt-console/mainwindow.h | 2 ++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/bacula/src/qt-console/mainwindow.cpp b/bacula/src/qt-console/mainwindow.cpp index 3750f01133..ae00cda623 100644 --- a/bacula/src/qt-console/mainwindow.cpp +++ b/bacula/src/qt-console/mainwindow.cpp @@ -37,15 +37,49 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { + QTreeWidgetItem *item, *topItem; setupUi(this); /* Setup UI defined by main.ui (designer) */ stackedWidget->setCurrentIndex(0); /* Dummy message ***FIXME*** remove a bit later */ textEdit->setPlainText("Hello Baculites\nThis is the main console window."); + lineEdit->setFocus(); /* Connect command line edit to input_line */ connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line())); - lineEdit->setFocus(); + connect(actionAbout_qt_console, SIGNAL(triggered()), this, SLOT(about())); + + connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this, + SLOT(treeItemClicked(QTreeWidgetItem *, int))); + connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, + SLOT(treeItemClicked(QTreeWidgetItem *, int))); + connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this, + SLOT(treeItemClicked(QTreeWidgetItem *, int))); + + + /* Dummy setup of treeWidget */ + treeWidget->clear(); + treeWidget->setColumnCount(1); + treeWidget->setHeaderLabel("Selection"); + topItem = new QTreeWidgetItem(treeWidget); + topItem->setText(0, "Rufus"); + item = new QTreeWidgetItem(topItem); + item->setText(0, "Console"); + item->setText(1, "0"); + item = new QTreeWidgetItem(topItem); + item->setText(0, "Restore"); + item->setText(1, "1"); + treeWidget->expandItem(topItem); } +void MainWindow::treeItemClicked(QTreeWidgetItem *item, int column) +{ + (void)column; + int index = item->text(1).toInt(); + if (index >= 0 && index < 2) { + stackedWidget->setCurrentIndex(index); + } +} + + /* * The user just finished typing a line in the command line edit box */ @@ -55,6 +89,14 @@ void MainWindow::input_line() lineEdit->clear(); /* clear the lineEdit box */ textEdit->append(cmdStr); /* append text on screen */ } +void MainWindow::about() +{ + QMessageBox::about(this, tr("About qt-console"), + tr("

Qt_console 0.1

" + "

Copyright © 2007 Free Software Foundation Europe e.V." + "

The qt-console is an administrative" + " interface to the Director.")); +} void set_textf(const char *fmt, ...) { diff --git a/bacula/src/qt-console/mainwindow.h b/bacula/src/qt-console/mainwindow.h index f5bfe11217..a5d90a134c 100644 --- a/bacula/src/qt-console/mainwindow.h +++ b/bacula/src/qt-console/mainwindow.h @@ -45,6 +45,8 @@ public: public slots: void input_line(); + void about(); + void treeItemClicked(QTreeWidgetItem *item, int column); private: QString m_UserInput; -- 2.39.5