# HG changeset patch # User Santeri Piippo # Date 1393194234 -7200 # Node ID 387b5e11c82532855ac693e1b8d1eced630f8ed3 # Parent d74279066305e71e77f8cc5a0d128ca595f1f536 - replaced the left-hand document list with a tab bar diff -r d74279066305 -r 387b5e11c825 src/Document.cc --- a/src/Document.cc Sun Feb 23 20:03:19 2014 +0200 +++ b/src/Document.cc Mon Feb 24 00:23:54 2014 +0200 @@ -125,7 +125,7 @@ { setImplicit (true); setSavePosition (-1); - setListItem (null); + setTabIndex (-1); setHistory (new History); m_History->setDocument (this); } @@ -1297,6 +1297,7 @@ if (g_win && f) { // A ton of stuff needs to be updated + log ("current: %1\n", m_curdoc); g_win->updateDocumentListItem (f); g_win->buildObjList(); g_win->updateTitle(); diff -r d74279066305 -r 387b5e11c825 src/Document.h --- a/src/Document.h Sun Feb 23 20:03:19 2014 +0200 +++ b/src/Document.h Mon Feb 24 00:23:54 2014 +0200 @@ -57,17 +57,17 @@ { properties: Q_OBJECT - PROPERTY (private, LDObjectList, Objects, LIST_OPS, STOCK_WRITE) + PROPERTY (private, LDObjectList, Objects, LIST_OPS, STOCK_WRITE) PROPERTY (private, History*, History, NO_OPS, STOCK_WRITE) - PROPERTY (private, LDObjectList, Vertices, LIST_OPS, STOCK_WRITE) + PROPERTY (private, LDObjectList, Vertices, LIST_OPS, STOCK_WRITE) PROPERTY (private, QList, References, LIST_OPS, STOCK_WRITE) PROPERTY (public, QString, Name, STR_OPS, STOCK_WRITE) PROPERTY (public, QString, FullPath, STR_OPS, STOCK_WRITE) PROPERTY (public, QString, DefaultName, STR_OPS, STOCK_WRITE) PROPERTY (public, bool, Implicit, BOOL_OPS, STOCK_WRITE) - PROPERTY (public, LDObjectList, Cache, LIST_OPS, STOCK_WRITE) + PROPERTY (public, LDObjectList, Cache, LIST_OPS, STOCK_WRITE) PROPERTY (public, long, SavePosition, NUM_OPS, STOCK_WRITE) - PROPERTY (public, QListWidgetItem*, ListItem, NO_OPS, STOCK_WRITE) + PROPERTY (public, int, TabIndex, NO_OPS, STOCK_WRITE) public: LDDocument(); diff -r d74279066305 -r 387b5e11c825 src/MainWindow.cc --- a/src/MainWindow.cc Sun Feb 23 20:03:19 2014 +0200 +++ b/src/MainWindow.cc Mon Feb 24 00:23:54 2014 +0200 @@ -67,10 +67,12 @@ MainWindow::MainWindow() { g_win = this; - m_renderer = new GLRenderer; - ui = new Ui_LDForgeUI; ui->setupUi (this); + m_updatingTabs = false; + m_renderer = new GLRenderer (this); + m_tabs = new QTabBar; + ui->verticalLayout->insertWidget (0, m_tabs); // Stuff the renderer into its frame QVBoxLayout* rendererLayout = new QVBoxLayout (ui->rendererFrame); @@ -78,7 +80,7 @@ connect (ui->objectList, SIGNAL (itemSelectionChanged()), this, SLOT (slot_selectionChanged())); connect (ui->objectList, SIGNAL (itemDoubleClicked (QListWidgetItem*)), this, SLOT (slot_editObject (QListWidgetItem*))); - connect (ui->fileList, SIGNAL (currentItemChanged (QListWidgetItem*, QListWidgetItem*)), this, SLOT (changeCurrentFile())); + connect (m_tabs, SIGNAL (currentChanged(int)), this, SLOT (changeCurrentFile())); // Init message log manager m_msglog = new MessageManager; @@ -892,7 +894,10 @@ void MainWindow::updateDocumentList() { - ui->fileList->clear(); + m_updatingTabs = true; + + while (m_tabs->count() > 0) + m_tabs->removeTab (0); for (LDDocument* f : g_loadedFiles) { @@ -900,18 +905,21 @@ if (f->isImplicit() && !gui_implicitfiles) continue; - // Add an item to the list for this file and store a pointer to it in - // the file, so we can find files by the list item. - ui->fileList->addItem (""); - QListWidgetItem* item = ui->fileList->item (ui->fileList->count() - 1); - f->setListItem (item); + // Add an item to the list for this file and store the tab index + // in the document so we can find documents by tab index. + f->setTabIndex (m_tabs->addTab ("")); updateDocumentListItem (f); } + + m_updatingTabs = false; } void MainWindow::updateDocumentListItem (LDDocument* f) { - if (f->getListItem() == null) + bool oldUpdatingTabs = m_updatingTabs; + m_updatingTabs = true; + + if (f->getTabIndex() == -1) { // We don't have a list item for this file, so the list either doesn't // exist yet or is out of date. Build the list now. @@ -921,18 +929,18 @@ // If this is the current file, it also needs to be the selected item on // the list. + log ("%1 <-> %2\n", f, getCurrentDocument()); if (f == getCurrentDocument()) - ui->fileList->setCurrentItem (f->getListItem()); + { + log ("New index: %1\n", f->getTabIndex()); + m_tabs->setCurrentIndex (f->getTabIndex()); + } - // If we list implicit files, draw them with a shade of gray to make them - // distinct. - if (f->isImplicit()) - f->getListItem()->setForeground (QColor (96, 96, 96)); + m_tabs->setTabText (f->getTabIndex(), f->getDisplayName()); - f->getListItem()->setText (f->getDisplayName()); - - // If the Document.has unsaved changes, draw a little icon next to it to mark that. - f->getListItem()->setIcon (f->hasUnsavedChanges() ? getIcon ("file-save") : QIcon()); + // If the document.has unsaved changes, draw a little icon next to it to mark that. + m_tabs->setTabIcon (f->getTabIndex(), f->hasUnsavedChanges() ? getIcon ("file-save") : QIcon()); + m_updatingTabs = oldUpdatingTabs; } // ============================================================================= @@ -940,13 +948,16 @@ // which file was picked and change to it. void MainWindow::changeCurrentFile() { + if (m_updatingTabs) + return; + LDDocument* f = null; - QListWidgetItem* item = ui->fileList->currentItem(); + int tabIndex = m_tabs->currentIndex(); // Find the file pointer of the item that was selected. for (LDDocument* it : g_loadedFiles) { - if (it->getListItem() == item) + if (it->getTabIndex() == tabIndex) { f = it; break; @@ -955,7 +966,7 @@ // If we picked the same file we're currently on, we don't need to do // anything. - if (!f || f == getCurrentDocument()) + if (f == null || f == getCurrentDocument()) return; LDDocument::setCurrent (f); diff -r d74279066305 -r 387b5e11c825 src/MainWindow.h --- a/src/MainWindow.h Sun Feb 23 20:03:19 2014 +0200 +++ b/src/MainWindow.h Mon Feb 24 00:23:54 2014 +0200 @@ -235,13 +235,15 @@ void closeEvent (QCloseEvent* ev); private: - GLRenderer* m_renderer; - LDObjectList m_sel; - QList m_quickColors; - QList m_colorButtons; - QList m_recentFiles; - MessageManager* m_msglog; - Ui_LDForgeUI* ui; + GLRenderer* m_renderer; + LDObjectList m_sel; + QList m_quickColors; + QList m_colorButtons; + QList m_recentFiles; + MessageManager* m_msglog; + Ui_LDForgeUI* ui; + QTabBar* m_tabs; + bool m_updatingTabs; private slots: void slot_selectionChanged(); diff -r d74279066305 -r 387b5e11c825 ui/ldforge.ui --- a/ui/ldforge.ui Sun Feb 23 20:03:19 2014 +0200 +++ b/ui/ldforge.ui Mon Feb 24 00:23:54 2014 +0200 @@ -20,17 +20,7 @@ - - - - - - 0 - 0 - - - - +