diff --git a/i18n/collett_en_US.ts b/i18n/collett_en_US.ts index b19b27d..6d661d9 100644 --- a/i18n/collett_en_US.ts +++ b/i18n/collett_en_US.ts @@ -112,7 +112,7 @@ Collett::GuiMain - + %1 %2 Version %3 @@ -120,7 +120,7 @@ Collett::GuiMainToolBar - + No Project @@ -145,7 +145,32 @@ - + + New Document + + + + + Open Document + + + + + Save Document + + + + + Rename Document + + + + + Documents + + + + Menu @@ -153,75 +178,70 @@ Collett::GuiStoryTree - - Rename - - - - + Add Scene - + Inside - + Before - + After - + Add Chapter - + Add Partition - + Add Book - + Here - + Add Page - + Rename Story Item - - New name: + + New Name: diff --git a/i18n/collett_nb_NO.ts b/i18n/collett_nb_NO.ts index 1bbd671..0ffe0a9 100644 --- a/i18n/collett_nb_NO.ts +++ b/i18n/collett_nb_NO.ts @@ -112,7 +112,7 @@ Collett::GuiMain - + %1 %2 Version %3 @@ -120,7 +120,7 @@ Collett::GuiMainToolBar - + No Project @@ -145,7 +145,32 @@ - + + New Document + + + + + Open Document + + + + + Save Document + + + + + Rename Document + + + + + Documents + + + + Menu @@ -153,75 +178,70 @@ Collett::GuiStoryTree - - Rename - - - - + Add Scene - + Inside - + Before - + After - + Add Chapter - + Add Partition - + Add Book - + Here - + Add Page - + Rename Story Item - - New name: + + New Name: diff --git a/src/core/icons.cpp b/src/core/icons.cpp index 8fac5d8..66d63a1 100644 --- a/src/core/icons.cpp +++ b/src/core/icons.cpp @@ -111,6 +111,12 @@ CollettIcons::CollettIcons() { "H11v2z" ); + // description_black_24dp.svg + m_svgPath["documents"] = QByteArray( + "M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8" + "v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z" + ); + // format_size_black_24dp.svg m_svgPath["formatText"] = QByteArray( "M9 4v3h5v12h3V7h5V4H9zm-6 8h3v7h3v-7h3V9H3v3z" diff --git a/src/editor/doceditor.cpp b/src/editor/doceditor.cpp index c45251c..01341b9 100644 --- a/src/editor/doceditor.cpp +++ b/src/editor/doceditor.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include namespace Collett { @@ -183,6 +184,15 @@ bool GuiDocEditor::hasDocument() const { return m_document != nullptr && !m_docUuid.isNull(); } +/**! + * @brief Check if this, or any child widget has focus + */ +bool GuiDocEditor::anyFocus() const { + if (this->hasFocus()) + return true; + return this->isAncestorOf(qApp->focusWidget()); +} + /** * Private Slots * ============= diff --git a/src/editor/doceditor.h b/src/editor/doceditor.h index 2c00130..c3daea7 100644 --- a/src/editor/doceditor.h +++ b/src/editor/doceditor.h @@ -55,6 +55,7 @@ class GuiDocEditor : public QWidget QUuid currentDocument() const; bool hasDocument() const; + bool anyFocus() const; signals: void popMessage(const Collett::Severity type, const QString &message); diff --git a/src/gui/maintoolbar.cpp b/src/gui/maintoolbar.cpp index 2989a7d..93d8a1d 100644 --- a/src/gui/maintoolbar.cpp +++ b/src/gui/maintoolbar.cpp @@ -22,12 +22,13 @@ #include "maintoolbar.h" #include "icons.h" +#include +#include #include -#include #include +#include #include -#include -#include +#include namespace Collett { @@ -42,7 +43,7 @@ GuiMainToolBar::GuiMainToolBar(QWidget *parent) m_projectName = new QLabel(tr("No Project")); this->setOrientation(Qt::Horizontal); - this->buildProjectMenu(); + this->buildMainMenu(); this->addWidget(stretch1); this->addWidget(m_projectName); this->addWidget(stretch2); @@ -58,23 +59,22 @@ void GuiMainToolBar::setProjectName(const QString &name) { * =============== */ -void GuiMainToolBar::buildProjectMenu() { +void GuiMainToolBar::buildMainMenu() { CollettIcons *icons = CollettIcons::instance(); - // Menu + // Project Menu m_projectMenu = new QMenu(this); - // New Project m_newProject = m_projectMenu->addAction(tr("New Project")); + m_newProject->setShortcut(QKeySequence("Ctrl+Shift+N")); - // Open Project m_openProject = m_projectMenu->addAction(tr("Open Project")); + m_openProject->setShortcut(QKeySequence("Ctrl+Shift+O")); - // Save Project m_saveProject = m_projectMenu->addAction(tr("Save Project")); + m_saveProject->setShortcut(QKeySequence("Ctrl+Shift+S")); - // Assemble m_projectButton = new QToolButton(this); m_projectButton->setText(tr("Project")); m_projectButton->setIcon(icons->icon("archive")); @@ -82,6 +82,28 @@ void GuiMainToolBar::buildProjectMenu() { m_projectButton->setPopupMode(QToolButton::InstantPopup); this->addWidget(m_projectButton); + // Documents Menu + m_docsMenu = new QMenu(this); + + m_newDocument = m_docsMenu->addAction(tr("New Document")); + m_newDocument->setShortcut(QKeySequence("Ctrl+N")); + + m_openDocument = m_docsMenu->addAction(tr("Open Document")); + m_openDocument->setShortcut(QKeySequence("Ctrl+O")); + + m_saveDocument = m_docsMenu->addAction(tr("Save Document")); + m_saveDocument->setShortcut(QKeySequence("Ctrl+S")); + + m_renameDocument = m_docsMenu->addAction(tr("Rename Document")); + m_renameDocument->setShortcut(QKeySequence("F2")); + + m_docsButton = new QToolButton(this); + m_docsButton->setText(tr("Documents")); + m_docsButton->setIcon(icons->icon("documents")); + m_docsButton->setMenu(m_docsMenu); + m_docsButton->setPopupMode(QToolButton::InstantPopup); + this->addWidget(m_docsButton); + } void GuiMainToolBar::buildMoreMenu() { diff --git a/src/gui/maintoolbar.h b/src/gui/maintoolbar.h index 40bdbd8..44a3d97 100644 --- a/src/gui/maintoolbar.h +++ b/src/gui/maintoolbar.h @@ -32,6 +32,7 @@ namespace Collett { +class GuiMain; class GuiMainToolBar : public QToolBar { Q_OBJECT @@ -52,13 +53,23 @@ class GuiMainToolBar : public QToolBar QAction *m_openProject; QAction *m_saveProject; + // Documents Menu + QToolButton *m_docsButton; + QMenu *m_docsMenu; + QAction *m_newDocument; + QAction *m_openDocument; + QAction *m_saveDocument; + QAction *m_renameDocument; + // DropDown Menu QToolButton *m_moreButton; QMenu *m_moreMenu; - void buildProjectMenu(); + void buildMainMenu(); void buildMoreMenu(); + friend class GuiMain; + }; } // namespace Collett diff --git a/src/gui/storytree.cpp b/src/gui/storytree.cpp index b7ee39f..798604e 100644 --- a/src/gui/storytree.cpp +++ b/src/gui/storytree.cpp @@ -33,6 +33,7 @@ #include #include #include +#include namespace Collett { @@ -54,13 +55,6 @@ GuiStoryTree::GuiStoryTree(QWidget *parent) this->setAlternatingRowColors(true); this->setExpandsOnDoubleClick(false); - // Item Actions - m_editItem = new QAction(tr("Rename"), this); - m_editItem->setShortcut(QKeySequence("F2")); - this->addAction(m_editItem); - connect(m_editItem, SIGNAL(triggered(bool)), - this, SLOT(doEditName(bool))); - // Connect the Context Menu this->setContextMenuPolicy(Qt::CustomContextMenu); connect(this, SIGNAL(customContextMenuRequested(QPoint)), @@ -77,6 +71,20 @@ void GuiStoryTree::setTreeModel(StoryModel *model) { this->setModel(m_model); } +/** + * Class Getters + * ============= + */ + +QModelIndex GuiStoryTree::firstSelectedIndex() { + QModelIndexList selections = this->selectedIndexes(); + if (!selections.isEmpty()) { + return selections.at(0); + } else { + return QModelIndex(); + } +} + /** * Class Private Slots * =================== @@ -202,21 +210,21 @@ void GuiStoryTree::doOpenContextMenu(const QPoint &pos) { void GuiStoryTree::doEditName(bool checked) { Q_UNUSED(checked); - QModelIndexList sel = this->selectedIndexes(); - if (sel.size() < 1) { + QModelIndex index = this->firstSelectedIndex(); + if (!index.isValid()) { qDebug() << "No item selected"; return; } - QString oldName = m_model->itemName(sel.at(0)); + QString oldName = m_model->itemName(index); qDebug() << "Requested rename of item" << oldName; bool ok; QString newName = QInputDialog::getText( - this, tr("Rename Story Item"), tr("New name:"), QLineEdit::Normal, oldName, &ok + this, tr("Rename Story Item"), tr("New Name:"), QLineEdit::Normal, oldName, &ok ); if (ok && !newName.isEmpty()) { - m_model->setItemName(sel.at(0), newName); + m_model->setItemName(index, newName); } } diff --git a/src/gui/storytree.h b/src/gui/storytree.h index adebbe0..e90046e 100644 --- a/src/gui/storytree.h +++ b/src/gui/storytree.h @@ -48,8 +48,14 @@ class GuiStoryTree : public QTreeView void setTreeModel(StoryModel *model); -private slots: + // Class Getters + + QModelIndex firstSelectedIndex(); + +public slots: void doEditName(bool checked); + +private slots: void doOpenContextMenu(const QPoint &pos); void doAddChild(StoryItem *item, StoryItem::ItemType type, StoryModel::AddLocation loc); diff --git a/src/guimain.cpp b/src/guimain.cpp index 9d87add..ed25a5a 100644 --- a/src/guimain.cpp +++ b/src/guimain.cpp @@ -73,6 +73,22 @@ GuiMain::GuiMain(QWidget *parent) : QMainWindow(parent) { connect(m_storyTree, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(storyTreeDoubleClick(const QModelIndex&))); + connect(m_mainToolBar->m_openDocument, SIGNAL(triggered()), + this, SLOT(openSelectedDocument())); + connect(m_mainToolBar->m_saveDocument, SIGNAL(triggered()), + this, SLOT(saveOpenDocument())); + connect(m_mainToolBar->m_renameDocument, SIGNAL(triggered()), + this, SLOT(renameDocument())); + + // Connect Actions to Capture Key Sequence + this->addAction(m_mainToolBar->m_newProject); + this->addAction(m_mainToolBar->m_openProject); + this->addAction(m_mainToolBar->m_saveProject); + this->addAction(m_mainToolBar->m_newDocument); + this->addAction(m_mainToolBar->m_openDocument); + this->addAction(m_mainToolBar->m_saveDocument); + this->addAction(m_mainToolBar->m_renameDocument); + // Finalise setWindowTitle( tr("%1 %2 Version %3").arg(qApp->applicationName(), "–", qApp->applicationVersion()) @@ -195,6 +211,30 @@ void GuiMain::closeEvent(QCloseEvent *event) { * ============= */ +void GuiMain::openSelectedDocument() { + if (!m_data->hasProject()) + return; + + QModelIndex index = m_storyTree->firstSelectedIndex(); + if (!index.isValid()) + return; + + this->openDocument(m_data->project()->storyModel()->itemHandle(index)); +} + +void GuiMain::saveOpenDocument() { + if (!m_data->hasProject()) + return; + if (m_docEditor->anyFocus()) + m_docEditor->saveDocument(); +} + +void GuiMain::renameDocument() { + if (!m_data->hasProject()) + return; + m_storyTree->doEditName(false); +} + void GuiMain::storyTreeDoubleClick(const QModelIndex &index) { if (!m_data->hasProject() || !index.isValid()) { return; diff --git a/src/guimain.h b/src/guimain.h index e760f2c..2274d42 100644 --- a/src/guimain.h +++ b/src/guimain.h @@ -82,6 +82,9 @@ class GuiMain : public QMainWindow private slots: + void openSelectedDocument(); + void saveOpenDocument(); + void renameDocument(); void storyTreeDoubleClick(const QModelIndex &index); };