diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 37d925662..d98876fad 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -62,7 +62,7 @@ opencs_units (view/world opencs_units_noqt (view/world dialoguesubview subviews - enumdelegate vartypedelegate recordstatusdelegate refrecordtypedelegate + enumdelegate vartypedelegate recordstatusdelegate refidtypedelegate datadisplaydelegate scripthighlighter ) @@ -80,7 +80,7 @@ opencs_units (view/settings proxyblock abstractwidget usersettingsdialog - editorpage + datadisplayformatpage windowpage ) diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index e82629ff2..937d9b341 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -264,13 +264,12 @@ void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id) /// \todo add an user setting to reuse sub views (on a per document basis or on a per top level view basis) SubView *view = mSubViewFactory.makeSubView (id, *mDocument); - view->setObjectName ("subview"); mSubViewWindow.addDockWidget (Qt::TopDockWidgetArea, view); connect (view, SIGNAL (focusId (const CSMWorld::UniversalId&)), this, SLOT (addSubView (const CSMWorld::UniversalId&))); - CSMSettings::UserSettings::instance().updateSettings("Editor", "Record Status Display"); + CSMSettings::UserSettings::instance().updateSettings("Display Format"); view->show(); } @@ -392,12 +391,14 @@ void CSVDoc::View::resizeViewHeight (int height) void CSVDoc::View::updateEditorSetting (const QString &settingName, const QString &settingValue) { - if (settingName == "Record Status Display") + if ( (settingName == "Record Status Display") || (settingName == "Referenceable ID Type Display") { foreach (QObject *view, mSubViewWindow.children()) { - if (view->objectName() == "subview") - dynamic_cast(view)->updateEditorSetting (settingName, settingValue); + CSVDoc::SubView *subview = dynamic_cast(view); + + if (subview) + subview->updateEditorSetting (settingName, settingValue); } } else if (settingName == "Width") diff --git a/apps/opencs/view/doc/viewmanager.cpp b/apps/opencs/view/doc/viewmanager.cpp index 5530b426b..6d06e4248 100644 --- a/apps/opencs/view/doc/viewmanager.cpp +++ b/apps/opencs/view/doc/viewmanager.cpp @@ -13,7 +13,7 @@ #include "../world/enumdelegate.hpp" #include "../world/vartypedelegate.hpp" #include "../world/recordstatusdelegate.hpp" -#include "../world/refrecordtypedelegate.hpp" +#include "../world/refidtypedelegate.hpp" #include "../settings/usersettingsdialog.hpp" #include "view.hpp" @@ -124,7 +124,7 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager) new CSVWorld::RecordStatusDelegateFactory() ); mDelegateFactories->add (CSMWorld::ColumnBase::Display_RefRecordType, - new CSVWorld::RefRecordTypeDelegateFactory() ); + new CSVWorld::RefIdTypeDelegateFactory() ); connect (&CSMSettings::UserSettings::instance(), SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)), this, SLOT (slotUpdateEditorSetting (const QString &, const QString &))); @@ -357,10 +357,6 @@ void CSVDoc::ViewManager::exitApplication (CSVDoc::View *view) void CSVDoc::ViewManager::slotUpdateEditorSetting (const QString &settingName, const QString &settingValue) { - if (settingName == "Record Status Display" || - settingName == "Width" || settingName == "Height") - { - foreach (CSVDoc::View *view, mViews) - view->updateEditorSetting (settingName, settingValue); - } + foreach (CSVDoc::View *view, mViews) + view->updateEditorSetting (settingName, settingValue); } diff --git a/apps/opencs/view/settings/usersettingsdialog.cpp b/apps/opencs/view/settings/usersettingsdialog.cpp index 64b9aacff..05072e45a 100644 --- a/apps/opencs/view/settings/usersettingsdialog.cpp +++ b/apps/opencs/view/settings/usersettingsdialog.cpp @@ -12,7 +12,7 @@ #include -#include "editorpage.hpp" +#include "datadisplayformatpage.hpp" #include "windowpage.hpp" #include "../../model/settings/support.hpp" @@ -86,7 +86,7 @@ void CSVSettings::UserSettingsDialog::buildPages() setDockOptions (QMainWindow::AllowNestedDocks); createPage(); - createPage(); + createPage(); } @@ -104,7 +104,8 @@ void CSVSettings::UserSettingsDialog::writeSettings() CSVSettings::AbstractPage *CSVSettings::UserSettingsDialog::getAbstractPage (int index) { - return dynamic_cast(mStackedWidget->widget(index)); + AbstractPage *page = dynamic_cast (mStackedWidget->widget (index)); + return page; } void CSVSettings::UserSettingsDialog::slotChangePage(QListWidgetItem *current, QListWidgetItem *previous) diff --git a/apps/opencs/view/settings/usersettingsdialog.hpp b/apps/opencs/view/settings/usersettingsdialog.hpp index a992dbdf8..cda08707b 100644 --- a/apps/opencs/view/settings/usersettingsdialog.hpp +++ b/apps/opencs/view/settings/usersettingsdialog.hpp @@ -9,8 +9,6 @@ #include "../../model/settings/usersettings.hpp" #include "../../model/settings/support.hpp" -#include "editorpage.hpp" - class QHBoxLayout; class AbstractWidget; class QStackedWidget; diff --git a/apps/opencs/view/world/enumdelegate.hpp b/apps/opencs/view/world/enumdelegate.hpp index 58f19ff78..b79516a09 100644 --- a/apps/opencs/view/world/enumdelegate.hpp +++ b/apps/opencs/view/world/enumdelegate.hpp @@ -14,6 +14,8 @@ namespace CSVWorld /// \brief Integer value that represents an enum and is interacted with via a combobox class EnumDelegate : public CommandDelegate { + protected: + std::vector > mValues; private: @@ -41,6 +43,7 @@ namespace CSVWorld class EnumDelegateFactory : public CommandDelegateFactory { + protected: std::vector > mValues; public: @@ -60,4 +63,4 @@ namespace CSVWorld } -#endif \ No newline at end of file +#endif diff --git a/apps/opencs/view/world/recordstatusdelegate.cpp b/apps/opencs/view/world/recordstatusdelegate.cpp index 243f509ef..7a84769bb 100644 --- a/apps/opencs/view/world/recordstatusdelegate.cpp +++ b/apps/opencs/view/world/recordstatusdelegate.cpp @@ -4,103 +4,16 @@ #include #include "../../model/settings/usersettings.hpp" -CSVWorld::RecordStatusDelegate::RecordStatusDelegate(QUndoStack &undoStack, QObject *parent) - : CommandDelegate (undoStack, parent) -{ - mModifiedIcon = new QIcon (":./modified.png"); - mAddedIcon = new QIcon (":./added.png"); - mDeletedIcon = new QIcon (":./removed.png"); - mBaseIcon = new QIcon (":./base.png"); - mIconSize = 16; - - //Offset values are most likely device-dependent. - //Need to replace with device-independent references. - mTextLeftOffset = 3; - mIconTopOffset = -3; - - mStatusDisplay = 0; //icons and text by default. Remove when implemented as a user preference - - mFont = QApplication::font(); - mFont.setPointSize(10); - - mFontMetrics = new QFontMetrics(mFont); - - mTextAlignment.setAlignment (Qt::AlignLeft | Qt::AlignVCenter ); -} - -void CSVWorld::RecordStatusDelegate::paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - painter->save(); - - QString text = ""; - QIcon *icon = 0; - - switch (index.data().toInt()) - { - case 0: // State_BaseOnly - text = "Base"; - icon = mBaseIcon; - break; - - case 1: // State_Modified - text = "Modified"; - icon = mModifiedIcon; - break; - - case 2: // State_Modified_Only - text = "Added"; - icon = mAddedIcon; - break; - - case 3: // State_Deleted - - case 4: // State_Erased - text = "Deleted"; - icon = mDeletedIcon; - break; - - default: - break; - } - - QRect textRect = option.rect; - QRect iconRect = option.rect; - - //for icon-only (1), default option.rect centers icon left-to-right - //otherwise, size option.rect to fit the icon, forcing left-alignment with text - iconRect.setTop (iconRect.top() + mIconTopOffset); - iconRect.setBottom (iconRect.top() + mIconSize); - - if (mStatusDisplay == 0 && (icon) ) - { - iconRect.setRight (iconRect.left()+ mIconSize*2); - textRect.setLeft (iconRect.right() + mTextLeftOffset *1.25); - } - else - textRect.setLeft (textRect.left() + mTextLeftOffset ); - - if ( (mStatusDisplay == 0 || mStatusDisplay == 1) && (icon) ) - painter->drawPixmap(iconRect.center().x()-10,iconRect.center().y()+2, icon->pixmap(mIconSize, mIconSize)); - - // icon + text or text only, or force text if no icon exists for status - if (mStatusDisplay == 0 || mStatusDisplay == 2 || !(icon) ) - { - painter->setFont(mFont); - painter->drawText(textRect, text, mTextAlignment); - } - - painter->restore(); -} - -QSize CSVWorld::RecordStatusDelegate::sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - return QSize(); -} +CSVWorld::RecordStatusDelegate::RecordStatusDelegate(const ValueList& values, + const IconList & icons, + QUndoStack &undoStack, QObject *parent) + : DataDisplayDelegate (values, icons, undoStack, parent) +{} CSVWorld::CommandDelegate *CSVWorld::RecordStatusDelegateFactory::makeDelegate (QUndoStack& undoStack, QObject *parent) const { - return new RecordStatusDelegate (undoStack, parent); + return new RecordStatusDelegate (mValues, mIcons, undoStack, parent); } void CSVWorld::RecordStatusDelegate::updateEditorSetting (const QString &settingName, const QString &settingValue) @@ -108,15 +21,21 @@ void CSVWorld::RecordStatusDelegate::updateEditorSetting (const QString &setting if (settingName == "Record Status Display") { if (settingValue == "Icon and Text") - mStatusDisplay = 0; + mDisplayMode = Mode_IconAndText; else if (settingValue == "Icon Only") - mStatusDisplay = 1; + mDoisplayMode = Mode_IconOnly; else if (settingValue == "Text Only") - mStatusDisplay = 2; - - else - mStatusDisplay = 0; + mDisplayMode = Mode_TextOnly; } } + +CSVWorld::RecordStatusDelegateFactory::RecordStatusDelegateFactory() +{ + DataDisplayDelegateFactory::add ( CSMWorld::RecordBase::State_BaseOnly, "Base", ":./base.png"); + DataDisplayDelegateFactory::add ( CSMWorld::RecordBase::State_Deleted, "Deleted", ":./removed.png"); + DataDisplayDelegateFactory::add ( CSMWorld::RecordBase::State_Erased, "Deleted", ":./removed.png"); + DataDisplayDelegateFactory::add ( CSMWorld::RecordBase::State_Modified, "Modified", ":./modified.png"); + DataDisplayDelegateFactory::add ( CSMWorld::RecordBase::State_ModifiedOnly, "Added", ":./added.png"); +} diff --git a/apps/opencs/view/world/recordstatusdelegate.hpp b/apps/opencs/view/world/recordstatusdelegate.hpp index b67226ad5..a0b279bbc 100644 --- a/apps/opencs/view/world/recordstatusdelegate.hpp +++ b/apps/opencs/view/world/recordstatusdelegate.hpp @@ -5,49 +5,36 @@ #include #include +#include "datadisplaydelegate.hpp" +#include "../../model/world/record.hpp" + class QIcon; class QFont; -class QFontMetrics; namespace CSVWorld { - class RecordStatusDelegate : public CommandDelegate + class RecordStatusDelegate : public DataDisplayDelegate { - QFont mFont; - QFontMetrics *mFontMetrics; - - QTextOption mTextAlignment; - - QIcon *mModifiedIcon; - QIcon *mAddedIcon; - QIcon *mDeletedIcon; - QIcon *mBaseIcon; - - int mStatusDisplay; - - int mIconSize; - int mIconTopOffset; - int mTextLeftOffset; - public: - explicit RecordStatusDelegate(QUndoStack& undoStack, QObject *parent = 0); - void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; - - QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const; + explicit RecordStatusDelegate(const ValueList& values, + const IconList& icons, + QUndoStack& undoStack, QObject *parent = 0); void updateEditorSetting (const QString &settingName, const QString &settingValue); }; - class RecordStatusDelegateFactory : public CommandDelegateFactory + class RecordStatusDelegateFactory : public DataDisplayDelegateFactory { public: + RecordStatusDelegateFactory(); + virtual CommandDelegate *makeDelegate (QUndoStack& undoStack, QObject *parent) const; ///< The ownership of the returned CommandDelegate is transferred to the caller. }; } -#endif // RECORDSTATUSDELEGATE_H +#endif // RECORDSTATUSDELEGATE_HPP diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 1ec0dde09..b26eac913 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -13,7 +13,7 @@ #include "../../model/world/idtable.hpp" #include "../../model/world/record.hpp" #include "recordstatusdelegate.hpp" - +#include "refidtypedelegate.hpp" #include "util.hpp" void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event) @@ -209,7 +209,23 @@ void CSVWorld::Table::updateEditorSetting (const QString &settingName, const QSt { if (settingName == "Record Status Display") { - dynamic_cast(this->itemDelegateForColumn(1))->updateEditorSetting (settingName, settingValue); - emit dataChanged(mModel->index(0,1), mModel->index(mModel->rowCount()-1, 1)); + RecordStatusDelegate *rsDelegate = dynamic_cast (itemDelegateForColumn(1)); + + if (rsDelegate) + { + rsDelegate->updateEditorSetting (settingName, settingValue); + emit dataChanged(mModel->index(0,1), mModel->index(mModel->rowCount()-1, 1)); + } + } + + if (settingName == "Referenceable ID Type Display") + { + RefIdTypeDelegate *refidDelegate = dynamic_cast (itemDelegateForColumn(2)); + + if (refidDelegate) + { + refidDelegate->updateEditorSetting (settingName, settingValue); + emit dataChanged(mModel->index(0,1), mModel->index(mModel->rowCount()-1, 1)); + } } } diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index d139ef74b..8c86acf31 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -27,6 +27,6 @@ void CSVWorld::TableSubView::rowActivated (const QModelIndex& index) void CSVWorld::TableSubView::updateEditorSetting(const QString &settingName, const QString &settingValue) { - if (settingName == "Record Status Display") + if ( (settingName == "Record Status Display") || settingName == "Referenceable ID Type Display" ) mTable->updateEditorSetting(settingName, settingValue); } diff --git a/files/opencs/resources.qrc b/files/opencs/resources.qrc index 926bda064..321413763 100644 --- a/files/opencs/resources.qrc +++ b/files/opencs/resources.qrc @@ -5,5 +5,25 @@ modified.png removed.png base.png + activator.png + apparatus.png + armor.png + book.png + clothing.png + container.png + creature.png + door.png + ingredient.png + leveled-creature.png + leveled-item.png + light.png + lockpick.png + miscellaneous.png + npc.png + potion.png + probe.png + repair.png + static.png + weapon.png