diff --git a/cbook.h b/cbook.h index 25581ae..2b94888 100644 --- a/cbook.h +++ b/cbook.h @@ -2,12 +2,15 @@ #define CBOOK_H +#include #include #include +#include -class cBook +class cBook : public QObject { + Q_OBJECT public: cBook(const QString& szTitle = ""); @@ -48,4 +51,6 @@ private: QDateTime m_targetDate; }; +Q_DECLARE_METATYPE(cBook*) + #endif // CBOOK_H diff --git a/cchapter.cpp b/cchapter.cpp index f745e87..aeb0cb1 100644 --- a/cchapter.cpp +++ b/cchapter.cpp @@ -104,7 +104,7 @@ bool cChapterList::load(cPartList* lpPartList) { QSqlQuery query; - query.prepare("SELECT id, partID, name, sortOrder, description, file FROM chapter;"); + query.prepare("SELECT id, partID, name, sortOrder, description, file FROM chapter ORDER BY sortOrder;"); if(!query.exec()) { myDebug << query.lastError().text(); diff --git a/cchapter.h b/cchapter.h index 8022cd8..aa2a08c 100644 --- a/cchapter.h +++ b/cchapter.h @@ -7,6 +7,7 @@ #include #include #include +#include class cChapter diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 66b644a..f946b5b 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -13,19 +13,25 @@ #include +#include + cMainWindow::cMainWindow(QWidget *parent) : QMainWindow(parent), - m_lpOutlineModel(0), ui(new Ui::cMainWindow), + m_lpOutlineModel(0), m_bUpdatingTab(false), m_lpStoryBook(0) { initUI(); createActions(); - m_lpStoryBook = new cStoryBook("c:/temp/qtStoryWriter/DerAdler"); - m_lpStoryBook->fillOutlineList(m_lpOutlineModel); + QString szPath = QDir::homePath() + QDir::separator() + "OneDrive - WINDESIGN" + QDir::separator() + "__BOOKS__" + QDir::separator() + "qtStoryWriter" + QDir::separator() + "DerAdler"; + m_lpStoryBook = new cStoryBook(szPath); + m_lpStoryBook->fillOutlineList(ui->m_lpOutline); + ui->m_lpOutline->expandAll(); + ui->m_lpOutline->resizeColumnToContents(0); + ui->m_lpOutline->resizeColumnToContents(1); updateWindowTitle(); diff --git a/cmainwindow.ui b/cmainwindow.ui index 3b7d773..5529465 100644 --- a/cmainwindow.ui +++ b/cmainwindow.ui @@ -44,7 +44,11 @@ - + + + false + + @@ -53,7 +57,7 @@ 0 0 - 69 + 79 477 @@ -66,7 +70,7 @@ 0 0 - 69 + 79 477 @@ -79,7 +83,7 @@ 0 0 - 69 + 79 477 diff --git a/cpart.cpp b/cpart.cpp index 5d0514c..631d33a 100644 --- a/cpart.cpp +++ b/cpart.cpp @@ -93,7 +93,7 @@ bool cPartList::load() { QSqlQuery query; - query.prepare("SELECT id, name, sortOrder, description, file FROM part;"); + query.prepare("SELECT id, name, sortOrder, description, file FROM part ORDER BY sortOrder;"); if(!query.exec()) { myDebug << query.lastError().text(); diff --git a/cpart.h b/cpart.h index d7177cf..618ed01 100644 --- a/cpart.h +++ b/cpart.h @@ -5,10 +5,12 @@ #include #include #include +#include -class cPart +class cPart : public QObject { + Q_OBJECT public: cPart(qint32 iID = -1); diff --git a/cscene.cpp b/cscene.cpp index 1fba3f5..b045467 100644 --- a/cscene.cpp +++ b/cscene.cpp @@ -117,6 +117,52 @@ QString cScene::file() return(m_szFile); } +QString cScene::stateText() +{ + return(stateText(m_state)); +} + +QString cScene::stateText(STATE state) const +{ + switch(state) + { + case cScene::STATE::STATE_unknown: + return(tr("unknown")); + case cScene::STATE::STATE_init: + return(tr("initialized")); + case cScene::STATE::STATE_progress: + return(tr("progress")); + case cScene::STATE::STATE_delayed: + return(tr("delayed")); + case cScene::STATE::STATE_finished: + return(tr("finished")); + } + return("unknown"); +} + +QColor cScene::stateColor() +{ + return(stateColor(m_state)); +} + +QColor cScene::stateColor(STATE state) const +{ + switch(state) + { + case cScene::STATE::STATE_unknown: + return(Qt::red); + case cScene::STATE::STATE_init: + return(QColor(127, 127, 255)); + case cScene::STATE::STATE_progress: + return(QColor(127, 255, 127)); + case cScene::STATE::STATE_delayed: + return(Qt::yellow); + case cScene::STATE::STATE_finished: + return(Qt::green); + } + return(Qt::darkRed); +} + cScene* cSceneList::add(const qint32& iID) { cScene* lpScene = find(iID); @@ -145,7 +191,7 @@ bool cSceneList::load(cChapterList* lpChapterList) { QSqlQuery query; - query.prepare("SELECT id, chapterID, name, sortOrder, description, state, startedAt, finishedAt, targetDate, file FROM scene;"); + query.prepare("SELECT id, chapterID, name, sortOrder, description, state, startedAt, finishedAt, targetDate, file FROM scene ORDER BY sortOrder;"); if(!query.exec()) { myDebug << query.lastError().text(); diff --git a/cscene.h b/cscene.h index be023cb..9d383d7 100644 --- a/cscene.h +++ b/cscene.h @@ -8,10 +8,14 @@ #include #include #include +#include +#include -class cScene +class cScene : public QObject { + Q_OBJECT + public: enum STATE { @@ -54,6 +58,10 @@ public: void setFile(const QString& szFile); QString file(); + QString stateText(); + QString stateText(STATE state) const; + QColor stateColor(); + QColor stateColor(STATE state) const; private: qint32 m_iID; cChapter* m_lpChapter; diff --git a/cstorybook.cpp b/cstorybook.cpp index d60e629..0667a7a 100644 --- a/cstorybook.cpp +++ b/cstorybook.cpp @@ -7,9 +7,11 @@ #include #include +#include #include +#include #include @@ -43,9 +45,18 @@ cStoryBook::~cStoryBook() bool cStoryBook::openDatabase() { + QString szDatabase = QString("%1%2storyBook.project").arg(m_szProjectPath).arg(QDir::separator()); + QFile file(szDatabase); + + if(!file.exists()) + { + myDebug << QObject::tr("project does not exist"); + return(false); + + } m_db = QSqlDatabase::addDatabase("QSQLITE"); m_db.setHostName("localhost"); - m_db.setDatabaseName(QString("%1%2storyBook.project").arg(m_szProjectPath).arg(QDir::separator())); + m_db.setDatabaseName(szDatabase); if(!m_db.open()) { @@ -334,20 +345,36 @@ QString cStoryBook::author() return(m_book.author()); } -bool cStoryBook::fillOutlineList(QStandardItemModel* lpModel) +bool cStoryBook::fillOutlineList(QTreeView* lpView) { QMap part; QMap chapter; + QStandardItemModel* lpModel = (QStandardItemModel*)lpView->model(); + QStandardItem* lpRootItem = lpModel->invisibleRootItem(); + QFont fontPart = lpRootItem->font(); + QFont fontChapter = lpRootItem->font(); + QFont fontScene = lpRootItem->font(); + QColor background(241, 241, 241); lpModel->clear(); + QStringList headerLabels = QStringList() << tr("") << tr(""); + lpModel->setHorizontalHeaderLabels(headerLabels); + + fontPart.setBold(true); + fontChapter.setItalic(true); + for(int x = 0;x < m_partList.count();x++) { cPart* lpPart = m_partList.at(x); - QStandardItem* lpItem = new QStandardItem(lpPart->name()); + QStandardItem* lpItem = new QStandardItem(lpPart->name()); lpItem->setData(QVariant::fromValue(lpPart)); + lpItem->setFont(fontPart); + lpItem->setBackground(QBrush(background)); part.insert(lpPart->id(), lpItem); lpModel->appendRow(lpItem); + qint16 z = lpRootItem->rowCount(); + lpView->setFirstColumnSpanned(lpModel->rowCount()-1, lpRootItem->index(), true); } for(int x = 0;x < m_chapterList.count();x++) @@ -359,8 +386,12 @@ bool cStoryBook::fillOutlineList(QStandardItemModel* lpModel) { QStandardItem* lpItem = new QStandardItem(lpChapter->name()); lpItem->setData(QVariant::fromValue(lpChapter)); + lpItem->setFont(fontChapter); + lpItem->setForeground(QBrush(Qt::darkBlue)); + lpItem->setBackground(QBrush(background)); chapter.insert(lpChapter->id(), lpItem); lpRoot->appendRow(lpItem); + lpView->setFirstColumnSpanned(lpRoot->rowCount()-1, lpRoot->index(), true); } } @@ -371,9 +402,18 @@ bool cStoryBook::fillOutlineList(QStandardItemModel* lpModel) if(lpRoot) { - QStandardItem* lpItem = new QStandardItem(lpScene->name()); - lpItem->setData(QVariant::fromValue(lpScene)); - lpRoot->appendRow(lpItem); + QList lpItems; + + lpItems << new QStandardItem(lpScene->name()); + lpItems[0]->setData(QVariant::fromValue(lpScene)); + lpItems[0]->setFont(fontScene); + lpItems[0]->setForeground(QBrush(Qt::blue)); + + lpItems << new QStandardItem(lpScene->stateText()); + lpItems[1]->setData(QVariant::fromValue(lpScene)); + lpItems[1]->setBackground(QBrush(lpScene->stateColor())); + lpItems[1]->setTextAlignment(Qt::AlignCenter); + lpRoot->appendRow(lpItems); } } diff --git a/cstorybook.h b/cstorybook.h index d9d7e39..2fa8228 100644 --- a/cstorybook.h +++ b/cstorybook.h @@ -8,14 +8,17 @@ #include "cscene.h" #include +#include +#include #include #include -class cStoryBook +class cStoryBook : public QObject { + Q_OBJECT public: cStoryBook(const QString& szProjectPath); ~cStoryBook(); @@ -26,7 +29,7 @@ public: QString title(); QString author(); - bool fillOutlineList(QStandardItemModel* lpModel); + bool fillOutlineList(QTreeView* lpView); private: QString m_szProjectPath; bool m_bIsOpen;