From 01aa493e29a3114b396b9855207a1dc242f79a5e Mon Sep 17 00:00:00 2001 From: shibakaneki Date: Wed, 1 Feb 2012 14:03:36 +0100 Subject: [PATCH] Implemented the Teacher Bar Document Preview widget --- src/adaptors/UBMetadataDcSubsetAdaptor.cpp | 3 +- src/core/UBSettings.cpp | 1 + src/core/UBSettings.h | 1 + src/document/UBDocumentProxy.cpp | 9 ++ src/document/UBDocumentProxy.h | 1 + src/gui/UBTBDocumentPreviewWidget.cpp | 134 ++++++++++++++++++--- src/gui/UBTBDocumentPreviewWidget.h | 29 ++++- src/gui/UBTeacherBarDataMgr.cpp | 10 +- src/gui/UBTeacherBarDataMgr.h | 9 ++ 9 files changed, 177 insertions(+), 20 deletions(-) diff --git a/src/adaptors/UBMetadataDcSubsetAdaptor.cpp b/src/adaptors/UBMetadataDcSubsetAdaptor.cpp index 0dbdd5c5..10ee3cc4 100644 --- a/src/adaptors/UBMetadataDcSubsetAdaptor.cpp +++ b/src/adaptors/UBMetadataDcSubsetAdaptor.cpp @@ -276,7 +276,6 @@ QMap UBMetadataDcSubsetAdaptor::load(QString pPath) qWarning() << "Document size not found, using default view size" << docSize; metadata.insert(UBSettings::documentSize, QVariant(docSize)); - } if (!updatedAtFound) @@ -284,6 +283,8 @@ QMap UBMetadataDcSubsetAdaptor::load(QString pPath) metadata.insert(UBSettings::documentUpdatedAt, date + "T00:00:00Z"); } + metadata.insert(UBSettings::documentDate, QVariant(date)); + return metadata; } diff --git a/src/core/UBSettings.cpp b/src/core/UBSettings.cpp index b9819d52..f218f22c 100644 --- a/src/core/UBSettings.cpp +++ b/src/core/UBSettings.cpp @@ -43,6 +43,7 @@ QString UBSettings::sessionKeywords = QString("sessionKeywords"); QString UBSettings::sessionLevel = QString("sessionLevel"); QString UBSettings::sessionTopic = QString("sessionTopic"); QString UBSettings::sessionAuthors = QString("sessionAuthors"); +QString UBSettings::documentDate = QString("date"); QString UBSettings::trashedDocumentGroupNamePrefix = QString("_Trash:"); diff --git a/src/core/UBSettings.h b/src/core/UBSettings.h index 21b4d4e1..fd25cd4b 100644 --- a/src/core/UBSettings.h +++ b/src/core/UBSettings.h @@ -160,6 +160,7 @@ class UBSettings : public QObject static QString sessionLevel; static QString sessionTopic; static QString sessionAuthors; + static QString documentDate; static QString trashedDocumentGroupNamePrefix; diff --git a/src/document/UBDocumentProxy.cpp b/src/document/UBDocumentProxy.cpp index aafcfeda..add97241 100644 --- a/src/document/UBDocumentProxy.cpp +++ b/src/document/UBDocumentProxy.cpp @@ -295,6 +295,15 @@ QString UBDocumentProxy::sessionAuthors() return QString(); } +QString UBDocumentProxy::documentDate() +{ + if(mMetaDatas.contains(UBSettings::documentDate)){ + return metaData(UBSettings::documentDate).toString(); + }else{ + return QString(); + } +} + bool UBDocumentProxy::isModified() const { return mIsModified; diff --git a/src/document/UBDocumentProxy.h b/src/document/UBDocumentProxy.h index a8ec9b3b..6686a4f3 100644 --- a/src/document/UBDocumentProxy.h +++ b/src/document/UBDocumentProxy.h @@ -59,6 +59,7 @@ class UBDocumentProxy : public QObject QString sessionTopic(); void setSessionAuthor(const QString& authors); QString sessionAuthors(); + QString documentDate(); QSize defaultDocumentSize() const; diff --git a/src/gui/UBTBDocumentPreviewWidget.cpp b/src/gui/UBTBDocumentPreviewWidget.cpp index 39d75199..e5610061 100644 --- a/src/gui/UBTBDocumentPreviewWidget.cpp +++ b/src/gui/UBTBDocumentPreviewWidget.cpp @@ -4,27 +4,119 @@ UBTBDocumentPreviewWidget::UBTBDocumentPreviewWidget(UBTeacherBarDataMgr *pDataMgr, QWidget *parent, const char *name):QWidget(parent) , mpPageViewButton(NULL) , mpEditButton(NULL) + , mpSessionLabel(NULL) + , mpSessionTitle(NULL) + , mpAuthorLabel(NULL) + , mpAuthors(NULL) + , mpCreationDate(NULL) + , mpTargetLabel(NULL) + , mpTarget(NULL) + , mpMetadataLabel(NULL) + , mpKeywordLabel(NULL) + , mpKeyword(NULL) + , mpLevelLabel(NULL) + , mpLevel(NULL) + , mpTopicLabel(NULL) + , mpTopic(NULL) + , mpLicense(NULL) + , mpContainer(NULL) { setObjectName(name); mpDataMgr = pDataMgr; setLayout(&mLayout); + mLayout.setContentsMargins(0, 0, 0, 0); - mpPageViewButton = new QPushButton(tr("Page View"), this); - mpPageViewButton->setObjectName("DockPaletteWidgetButton"); - mPageLayout.addStretch(1); - mPageLayout.addWidget(mpPageViewButton, 0); - mPageLayout.addStretch(1); - mLayout.addLayout(&mPageLayout); + mpContainer = new QWidget(this); + mpContainer->setLayout(&mContainerLayout); + mpContainer->setObjectName("UBTeacherBarPreviewWidget"); + + // Session Title + mpSessionLabel = new QLabel(tr("Session"), mpContainer); + mpSessionLabel->setAlignment(Qt::AlignRight); + mpSessionLabel->setObjectName("UBTeacherBarPreviewSubtitle"); + mContainerLayout.addWidget(mpSessionLabel, 0); + mpSessionTitle = new QLabel(mpContainer); + mpSessionTitle->setWordWrap(true); + mpSessionTitle->setAlignment(Qt::AlignRight); + mpSessionTitle->setObjectName("UBTeacherBarPreviewTitle"); + mContainerLayout.addWidget(mpSessionTitle, 0); + mContainerLayout.addWidget(&mTitleSeparator, 0); + + // Author(s) + mpAuthorLabel = new QLabel(tr("Author(s)"), mpContainer); + mpAuthorLabel->setObjectName("UBTeacherBarPreviewSubtitle"); + mContainerLayout.addWidget(mpAuthorLabel, 0); + mpAuthors = new QLabel(mpContainer); + mpAuthors->setWordWrap(true); + mpAuthors->setStyleSheet("padding-left:5px;"); + mContainerLayout.addWidget(mpAuthors, 0); + mContainerLayout.addWidget(&mAuthorSeparator, 0); + + // Dates + mpCreationDate = new QLabel(tr("Created on: "), mpContainer); + mpCreationDate->setStyleSheet("padding-left:5px;"); + mContainerLayout.addWidget(mpCreationDate); + mContainerLayout.addWidget(&mDateSeparator, 0); + + // Target + mpTargetLabel = new QLabel(tr("Target"), mpContainer); + mpTargetLabel->setObjectName("UBTeacherBarPreviewSubtitle"); + mContainerLayout.addWidget(mpTargetLabel,0); + mpTarget = new QTextEdit(mpContainer); + mpTarget->setReadOnly(true); + mContainerLayout.addWidget(mpTarget, 1); + mContainerLayout.addWidget(&mTargetSeparator, 0); + + // Metadata + mpMetadataLabel = new QLabel(tr("Metadata"), mpContainer); + mpMetadataLabel->setObjectName("UBTeacherBarPreviewSubtitle"); + mContainerLayout.addWidget(mpMetadataLabel, 0); + + // Keyword + mpKeywordLabel = new QLabel(tr("Keywords:"), mpContainer); + mpKeywordLabel->setStyleSheet("padding-left:5px;"); + mpKeyword = new QLabel(mpContainer); + mpKeyword->setWordWrap(true); + mKeywordLayout.addWidget(mpKeywordLabel, 0); + mKeywordLayout.addWidget(mpKeyword, 1); + mContainerLayout.addLayout(&mKeywordLayout, 0); + + // Level + mpLevelLabel = new QLabel(tr("Level:"), mpContainer); + mpLevelLabel->setStyleSheet("padding-left:5px;"); + mpLevel = new QLabel(mpContainer); + mpLevel->setWordWrap(true); + mLevelLayout.addWidget(mpLevelLabel, 0); + mLevelLayout.addWidget(mpLevel, 1); + mContainerLayout.addLayout(&mLevelLayout, 0); - // TODO : Add the elements here + // Topic + mpTopicLabel = new QLabel(tr("Topic:"), mpContainer); + mpTopicLabel->setStyleSheet("padding-left:5px;"); + mpTopic = new QLabel(mpContainer); + mpTopic->setWordWrap(true); + mTopicLayout.addWidget(mpTopicLabel, 0); + mTopicLayout.addWidget(mpTopic, 1); + mContainerLayout.addLayout(&mTopicLayout, 0); + mContainerLayout.addWidget(&mMetadataSeparator, 0); + // License + mpLicense = new UBTBLicenseWidget(mpContainer); + mContainerLayout.addWidget(mpLicense, 0); + + mLayout.addWidget(mpContainer, 1); + + mpPageViewButton = new QPushButton(tr("Page View"), this); + mpPageViewButton->setObjectName("DockPaletteWidgetButton"); mpEditButton = new QPushButton(tr("Edit"), this); mpEditButton->setObjectName("DockPaletteWidgetButton"); - mPreviewLayout.addStretch(1); - mPreviewLayout.addWidget(mpEditButton, 0); - mPreviewLayout.addStretch(1); - mLayout.addLayout(&mPreviewLayout); + + mButtonsLayout.addWidget(mpPageViewButton, 0); + mButtonsLayout.addWidget(mpEditButton, 0); + mButtonsLayout.addStretch(1); + + mLayout.addLayout(&mButtonsLayout, 0); connect(mpPageViewButton, SIGNAL(clicked()), this, SLOT(onPageView())); connect(mpEditButton, SIGNAL(clicked()), this, SLOT(onEdit())); @@ -32,8 +124,7 @@ UBTBDocumentPreviewWidget::UBTBDocumentPreviewWidget(UBTeacherBarDataMgr *pDataM UBTBDocumentPreviewWidget::~UBTBDocumentPreviewWidget() { - DELETEPTR(mpPageViewButton); - DELETEPTR(mpEditButton); + } void UBTBDocumentPreviewWidget::onEdit() @@ -48,10 +139,23 @@ void UBTBDocumentPreviewWidget::onPageView() void UBTBDocumentPreviewWidget::updateFields() { - + mpSessionTitle->setText(mpDataMgr->sessionTitle()); + mpAuthors->setText(mpDataMgr->authors()); + mpCreationDate->setText(tr("Creation Date: %0").arg(mpDataMgr->creationDate())); + mpTarget->setText(mpDataMgr->sessionTarget()); + mpLicense->setLicense(mpDataMgr->sessionLicence()); + mpKeyword->setText(mpDataMgr->keywords()); + mpLevel->setText(mpDataMgr->level()); + mpTopic->setText(mpDataMgr->topic()); } void UBTBDocumentPreviewWidget::clearFields() { - + mpSessionTitle->setText(""); + mpAuthors->setText(""); + mpCreationDate->setText(""); + mpTarget->setText(""); + mpKeyword->setText(""); + mpLevel->setText(""); + mpTopic->setText(""); } diff --git a/src/gui/UBTBDocumentPreviewWidget.h b/src/gui/UBTBDocumentPreviewWidget.h index 99959afa..f2115c72 100644 --- a/src/gui/UBTBDocumentPreviewWidget.h +++ b/src/gui/UBTBDocumentPreviewWidget.h @@ -24,10 +24,35 @@ private slots: private: QVBoxLayout mLayout; - QHBoxLayout mPageLayout; - QHBoxLayout mPreviewLayout; + QHBoxLayout mButtonsLayout; + + QWidget* mpContainer; + QVBoxLayout mContainerLayout; QPushButton* mpPageViewButton; QPushButton* mpEditButton; + QLabel* mpSessionLabel; + QLabel* mpSessionTitle; + UBTBSeparator mTitleSeparator; + QLabel* mpAuthorLabel; + QLabel* mpAuthors; + UBTBSeparator mAuthorSeparator; + QLabel* mpCreationDate; + UBTBSeparator mDateSeparator; + QLabel* mpTargetLabel; + QTextEdit* mpTarget; + UBTBSeparator mTargetSeparator; + QLabel* mpMetadataLabel; + QHBoxLayout mKeywordLayout; + QLabel* mpKeywordLabel; + QLabel* mpKeyword; + QHBoxLayout mLevelLayout; + QLabel* mpLevelLabel; + QLabel* mpLevel; + QHBoxLayout mTopicLayout; + QLabel* mpTopicLabel; + QLabel* mpTopic; + UBTBSeparator mMetadataSeparator; + UBTBLicenseWidget* mpLicense; UBTeacherBarDataMgr* mpDataMgr; }; diff --git a/src/gui/UBTeacherBarDataMgr.cpp b/src/gui/UBTeacherBarDataMgr.cpp index 5d951d77..dd1f2b44 100644 --- a/src/gui/UBTeacherBarDataMgr.cpp +++ b/src/gui/UBTeacherBarDataMgr.cpp @@ -1,3 +1,5 @@ +#include + #include "UBTeacherBarDataMgr.h" #include "core/UBApplication.h" @@ -59,7 +61,6 @@ void UBTeacherBarDataMgr::saveContent() documentProxy->setSessionTitle(mSessionTitle); documentProxy->setSessionTarget(mSessionTarget); documentProxy->setSessionLicence(QString("%0").arg(mSessionLicence)); - qDebug() << "Saving keywords: " << mKeywords; documentProxy->setSessionKeywords(mKeywords); documentProxy->setSessionLevel(mLevel); documentProxy->setSessionTopic(mTopic); @@ -82,10 +83,15 @@ void UBTeacherBarDataMgr::loadContent(bool docChanged) mSessionTarget = documentProxy->sessionTarget(); mSessionLicence = (eLicense)documentProxy->sessionLicence().toInt(); mKeywords = documentProxy->sessionKeywords(); - qDebug() << "Keywords loaded: " << mKeywords << " (" << documentProxy->sessionKeywords() << ")"; mLevel = documentProxy->sessionLevel(); mTopic = documentProxy->sessionTopic(); mAuthors = documentProxy->sessionAuthors(); + if("" != documentProxy->documentDate()){ + mCreationDate = documentProxy->documentDate(); + }else{ + mCreationDate = QDate::currentDate().toString("yyyy-MM-dd"); + } + } // Page Title diff --git a/src/gui/UBTeacherBarDataMgr.h b/src/gui/UBTeacherBarDataMgr.h index b182e892..900dfb38 100644 --- a/src/gui/UBTeacherBarDataMgr.h +++ b/src/gui/UBTeacherBarDataMgr.h @@ -115,6 +115,13 @@ public: void setAuthors(const QString& authors){mAuthors = authors;} QString authors(){return mAuthors;} + // Creation Date + void setCreationDate(const QString& date){mCreationDate = date;} + QString creationDate(){return mCreationDate;} + + // Last Modification + void setLastModificationDate(const QString& date){mLastModif = date;} + QString lastModificationDate(){return mLastModif;} // Others void clearLists(); @@ -131,6 +138,8 @@ private: QString mLevel; QString mTopic; QString mAuthors; + QString mCreationDate; + QString mLastModif; QVector mActionList; QVector mUrlList;