*/
#include "bat.h"
+#include "medialist/medialist.h"
MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
{
mainWin = this;
setupUi(this); /* Setup UI defined by main.ui (designer) */
+ treeWidget->clear();
+ treeWidget->setColumnCount(1);
+ treeWidget->setHeaderLabel("Select Page");
- createStackedWidgets();
+ m_pages = 0;
+ createPages();
resetFocus();
m_console->connect();
}
-void MainWin::createStackedWidgets()
+void MainWin::createPages()
{
+ DIRRES *dir;
QTreeWidgetItem *item, *topItem;
- m_console = new Console(stackedWidget);
- stackedWidget->addWidget(m_console);
- bRestore *brestore = new bRestore(stackedWidget);
- stackedWidget->addWidget(brestore);
+ /* Create console tree stacked widget item */
+ m_console = new Console(stackedWidget);
+ /* Console is special -> needs director*/
/* Just take the first Director */
LockRes();
- DIRRES *dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
+ dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
m_console->setDirRes(dir);
UnlockRes();
- /* ***FIXME*** Dummy setup of treeWidget */
- treeWidget->clear();
- treeWidget->setColumnCount(1);
- treeWidget->setHeaderLabel("Selection");
- topItem = new QTreeWidgetItem(treeWidget);
- topItem->setText(0, dir->name());
+ /* The top tree item representing the director */
+ topItem = createTopPage(dir->name());
topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png")));
- item = new QTreeWidgetItem(topItem);
- m_console->setTreeItem(item);
- item->setText(0, "Console");
- item->setText(1, "0");
+
+ /* Create Tree Widget Item */
+ item = createPage("Console", topItem);
+ m_console->SetPassedValues(stackedWidget, item, m_pages++ );
+
+ /* Append to bstacklist */
+ m_bstacklist.append(m_console);
+
+ /* Set BatStack m_treeItem */
QBrush redBrush(Qt::red);
item->setForeground(0, redBrush);
- item = new QTreeWidgetItem(topItem);
- item->setText(0, "brestore");
- item->setText(1, "1");
- treeWidget->expandItem(topItem);
+ /*
+ * Now with the console created, on with the rest, these are easy
+ * All should be
+ * 1. create tree widget item
+ * 2. create object passing pointer to tree widget item (modified constructors to pass QTreeWidget pointers)
+ * 3. append to stacklist
+ * And it can even be done in one line.
+ */
+
+ /* brestore */
+ m_bstacklist.append(new bRestore(stackedWidget,
+ createPage("brestore", topItem), m_pages++ ));
+
+ /* lastly for now, the medialist */
+ m_bstacklist.append(new MediaList(stackedWidget, m_console,
+ createPage("Storage Tree", topItem ), m_pages++));
+
+ /* Iterate through and add to the stack */
+ for (QList<BatStack*>::iterator bstackItem = m_bstacklist.begin();
+ bstackItem != m_bstacklist.end(); ++bstackItem ) {
+ (*bstackItem)->AddTostack();
+ }
+
+ treeWidget->expandItem(topItem);
stackedWidget->setCurrentIndex(0);
}
+/* Create a root Tree Widget */
+QTreeWidgetItem *MainWin::createTopPage(char *name )
+{
+ QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget);
+ item->setText(0, name);
+ 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)
+{
+ QTreeWidgetItem *item = new QTreeWidgetItem(parent);
+ item->setText(0, name);
+ return item;
+}
+
/*
* Handle up and down arrow keys for the command line
* history.
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)));
connect(actionLabel, SIGNAL(triggered()), this, SLOT(labelDialogClicked()));
connect(actionRun, SIGNAL(triggered()), this, SLOT(runDialogClicked()));
connect(actionRestore, SIGNAL(triggered()), this, SLOT(restoreDialogClicked()));
+ connect(actionPullWindowOut, SIGNAL(triggered()), this, SLOT(pullWindowOutButton()));
}
/*
void MainWin::treeItemClicked(QTreeWidgetItem *item, int column)
{
- (void)column;
- int index = item->text(1).toInt();
- if (index >= 0 && index < 4) {
- stackedWidget->setCurrentIndex(index);
+ column+=0;
+ /* Use tree item's Qt::UserRole to get treeindex */
+ int treeindex = item->data(column, Qt::UserRole).toInt();
+ int stackindex=stackedWidget->indexOf( m_bstacklist[treeindex] );
+ if( stackindex >= 0 ){
+ stackedWidget->setCurrentIndex(stackindex);
}
+ /* run the virtual function in case this class overrides it */
+ m_bstacklist[treeindex]->PgSeltreeWidgetClicked();
}
/*
void MainWin::treeItemDoubleClicked(QTreeWidgetItem *item, int column)
{
(void)column;
- int index = item->text(1).toInt();
- /* ***FIXME**** make this automatic */
- if (index >= 0 && index < 4) {
- stackedWidget->setCurrentIndex(index);
+ int treeindex = item->data(column, Qt::UserRole).toInt();
+
+ /* Use tree item's Qt::UserRole to get treeindex */
+ if ( m_bstacklist[treeindex]->isStacked() == true ){
+ m_bstackpophold=m_bstacklist[treeindex];
+ /* Create a popup menu before pulling window out */
+ QMenu *popup = new QMenu( treeWidget );
+ connect(popup->addAction("Pull Window Out"), SIGNAL(triggered()), this, SLOT(pullWindowOut()));
+ popup->exec(QCursor::pos());
+ } else {
+ /* Just pull it back in without prompting */
+ m_bstacklist[treeindex]->Togglestack();
}
+ /* Here is the virtual function so that different classes can do different things */
+ m_bstacklist[treeindex]->PgSeltreeWidgetDoubleClicked();
}
void MainWin::labelDialogClicked()
void MainWin::about()
{
QMessageBox::about(this, tr("About bat"),
- tr("<br><h2>bat 0.1</h2>"
+ tr("<br><h2>bat 0.2, by Kern Sibbald</h2>"
"<p>Copyright © " BYEAR " Free Software Foundation Europe e.V."
"<p>The <b>bat</b> is an administrative console"
" interface to the Director."));
{
statusBar()->showMessage(buf);
}
+
+void MainWin::pullWindowOut()
+{
+ m_bstackpophold->Togglestack();
+}
+
+void MainWin::pullWindowOutButton()
+{
+ int curindex = stackedWidget->currentIndex();
+ QList<BatStack*>::iterator bstackItem = m_bstacklist.begin();
+
+ while ((bstackItem != m_bstacklist.end())){
+ if (curindex == stackedWidget->indexOf(*bstackItem)) {
+ (*bstackItem)->Togglestack();
+ break;
+ }
+ ++bstackItem;
+ }
+}