diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index cec3756a3..d8ca6c409 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -61,7 +61,9 @@ opencs_units (view/world ) opencs_units_noqt (view/world - dialoguesubview subviews enumdelegate vartypedelegate scripthighlighter recordstatusdelegate + dialoguesubview subviews + enumdelegate vartypedelegate recordstatusdelegate refidtypedelegate datadisplaydelegate + scripthighlighter ) @@ -78,7 +80,7 @@ opencs_units (view/settings proxyblock abstractwidget usersettingsdialog - editorpage + datadisplayformatpage windowpage ) diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index b73fbfdf4..d106110d0 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include "settingcontainer.hpp" diff --git a/apps/opencs/model/world/columnbase.hpp b/apps/opencs/model/world/columnbase.hpp index e71e633a4..280341216 100644 --- a/apps/opencs/model/world/columnbase.hpp +++ b/apps/opencs/model/world/columnbase.hpp @@ -42,7 +42,8 @@ namespace CSMWorld Display_ClothingType, Display_CreatureType, Display_WeaponType, - Display_RecordState + Display_RecordState, + Display_RefRecordType }; std::string mTitle; diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index e4936afa6..a51f2f00c 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -44,7 +44,7 @@ CSMWorld::RefIdCollection::RefIdCollection() mColumns.push_back (RefIdColumn ("*", ColumnBase::Display_RecordState, ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue, false, false)); baseColumns.mModified = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Type", ColumnBase::Display_Integer, + mColumns.push_back (RefIdColumn ("Type", ColumnBase::Display_RefRecordType, ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue, false, false)); baseColumns.mType = &mColumns.back(); diff --git a/apps/opencs/model/world/universalid.cpp b/apps/opencs/model/world/universalid.cpp index b5efe6e22..ef32681a0 100644 --- a/apps/opencs/model/world/universalid.cpp +++ b/apps/opencs/model/world/universalid.cpp @@ -86,6 +86,8 @@ namespace { CSMWorld::UniversalId::Class_None, CSMWorld::UniversalId::Type_None, 0 } // end marker }; + + static const unsigned int IDARG_SIZE = sizeof (sIdArg) / sizeof (TypeData); } CSMWorld::UniversalId::UniversalId (const std::string& universalId) @@ -264,6 +266,26 @@ std::string CSMWorld::UniversalId::toString() const return stream.str(); } + +std::pair CSMWorld::UniversalId::getIdArgPair (unsigned int index) +{ + std::pair retPair; + + if ( index < IDARG_SIZE ) + { + retPair.first = sIdArg[index].mType; + retPair.second = sIdArg[index].mName; + } + + return retPair; +} + +unsigned int CSMWorld::UniversalId::getIdArgSize() +{ + return IDARG_SIZE; +} + + bool CSMWorld::operator== (const CSMWorld::UniversalId& left, const CSMWorld::UniversalId& right) { return left.isEqual (right); @@ -282,4 +304,4 @@ bool CSMWorld::operator< (const UniversalId& left, const UniversalId& right) std::ostream& CSMWorld::operator< (std::ostream& stream, const CSMWorld::UniversalId& universalId) { return stream << universalId.toString(); -} \ No newline at end of file +} diff --git a/apps/opencs/model/world/universalid.hpp b/apps/opencs/model/world/universalid.hpp index bd6fdeb00..9fae0a9f4 100644 --- a/apps/opencs/model/world/universalid.hpp +++ b/apps/opencs/model/world/universalid.hpp @@ -124,6 +124,9 @@ namespace CSMWorld std::string getTypeName() const; std::string toString() const; + + static std::pair getIdArgPair (unsigned int index); + static unsigned int getIdArgSize (); }; bool operator== (const UniversalId& left, const UniversalId& right); diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index bcc020350..43f068042 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -267,13 +267,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(); } @@ -400,12 +399,15 @@ 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); + // not all mSubviewWindow children are CSVDoc::Subview objects + 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 bf9da68a0..6d06e4248 100644 --- a/apps/opencs/view/doc/viewmanager.cpp +++ b/apps/opencs/view/doc/viewmanager.cpp @@ -13,6 +13,7 @@ #include "../world/enumdelegate.hpp" #include "../world/vartypedelegate.hpp" #include "../world/recordstatusdelegate.hpp" +#include "../world/refidtypedelegate.hpp" #include "../settings/usersettingsdialog.hpp" #include "view.hpp" @@ -122,6 +123,9 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager) mDelegateFactories->add (CSMWorld::ColumnBase::Display_RecordState, new CSVWorld::RecordStatusDelegateFactory() ); + mDelegateFactories->add (CSMWorld::ColumnBase::Display_RefRecordType, + new CSVWorld::RefIdTypeDelegateFactory() ); + connect (&CSMSettings::UserSettings::instance(), SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)), this, SLOT (slotUpdateEditorSetting (const QString &, const QString &))); } @@ -353,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/abstractblock.hpp b/apps/opencs/view/settings/abstractblock.hpp index 36108d752..361339fe2 100644 --- a/apps/opencs/view/settings/abstractblock.hpp +++ b/apps/opencs/view/settings/abstractblock.hpp @@ -43,7 +43,7 @@ namespace CSVSettings protected: - /// Creates the layout which for the blocks QGroupBox + /// Creates the layout for the block's QGroupBox QLayout *createLayout (Orientation direction, bool isZeroMargin, QWidget* parent = 0); /// Creates widgets that exist as direct children of the block diff --git a/apps/opencs/view/settings/abstractwidget.cpp b/apps/opencs/view/settings/abstractwidget.cpp index 94044e267..f268d3b27 100644 --- a/apps/opencs/view/settings/abstractwidget.cpp +++ b/apps/opencs/view/settings/abstractwidget.cpp @@ -19,7 +19,7 @@ void CSVSettings::AbstractWidget::buildLabelAndWidget (QWidget *widget, WidgetDe if (!(def.caption.isEmpty() || noLabel) ) { - QLabel *label = new QLabel (def.caption, dynamic_cast(parent())); + QLabel *label = new QLabel (def.caption, &dynamic_cast( *parent())); label->setBuddy (widget); mLayout->addWidget (label); diff --git a/apps/opencs/view/settings/datadisplayformatpage.cpp b/apps/opencs/view/settings/datadisplayformatpage.cpp new file mode 100755 index 000000000..cf25237f9 --- /dev/null +++ b/apps/opencs/view/settings/datadisplayformatpage.cpp @@ -0,0 +1,57 @@ +#include "datadisplayformatpage.hpp" +#include "groupblock.hpp" +#include "../../model/settings/usersettings.hpp" + +CSVSettings::DataDisplayFormatPage::DataDisplayFormatPage(QWidget* parent) : + AbstractPage("Display Format", parent) +{ + setupUi(); +} + +CSVSettings::GroupBlockDef *CSVSettings::DataDisplayFormatPage::setupDataDisplay( const QString &title) +{ + GroupBlockDef *statusBlock = new GroupBlockDef(QString(title)); + + SettingsItemDef *statusItem = new SettingsItemDef (statusBlock->title, "Icon and Text"); + *(statusItem->valueList) << QString("Icon and Text") << QString("Icon Only") << QString("Text Only"); + + WidgetDef statusWidget (Widget_RadioButton); + statusWidget.valueList = statusItem->valueList; + + statusItem->widget = statusWidget; + + statusBlock->settingItems << statusItem; + + statusBlock->isZeroMargin = false; + + return statusBlock; +} + + +void CSVSettings::DataDisplayFormatPage::setupUi() +{ + + mAbstractBlocks << buildBlock (setupDataDisplay ("Record Status Display")); + mAbstractBlocks << buildBlock (setupDataDisplay ("Referenceable ID Type Display")); + + foreach (AbstractBlock *block, mAbstractBlocks) + { + connect (block, SIGNAL (signalUpdateSetting (const QString &, const QString &)), + this, SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)) ); + } + + connect ( this, + SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &)), + &(CSMSettings::UserSettings::instance()), + SIGNAL ( signalUpdateEditorSetting (const QString &, const QString &))); + +} + +void CSVSettings::DataDisplayFormatPage::initializeWidgets (const CSMSettings::SettingMap &settings) +{ + //iterate each item in each blocks in this section + //validate the corresponding setting against the defined valuelist if any. + for (AbstractBlockList::Iterator it_block = mAbstractBlocks.begin(); + it_block != mAbstractBlocks.end(); ++it_block) + (*it_block)->updateSettings (settings); +} diff --git a/apps/opencs/view/settings/datadisplayformatpage.hpp b/apps/opencs/view/settings/datadisplayformatpage.hpp new file mode 100755 index 000000000..b785bbd23 --- /dev/null +++ b/apps/opencs/view/settings/datadisplayformatpage.hpp @@ -0,0 +1,33 @@ +#ifndef EDITORPAGE_HPP +#define EDITORPAGE_HPP + +#include "support.hpp" +#include "abstractpage.hpp" + +namespace CSVSettings +{ + class DataDisplayFormatPage : public AbstractPage + { + Q_OBJECT + + public: + explicit DataDisplayFormatPage(QWidget *parent = 0); + + void initializeWidgets (const CSMSettings::SettingMap &settings); + void setupUi(); + + private: + + /// User preference view of the record status delegate's icon / text setting + GroupBlockDef *setupDataDisplay(const QString &); + + signals: + + /// Signals up for changes to editor application-level settings + void signalUpdateEditorSetting (const QString &settingName, const QString &settingValue); + + public slots: + }; +} + +#endif // EDITORPAGE_HPP diff --git a/apps/opencs/view/settings/groupblock.cpp b/apps/opencs/view/settings/groupblock.cpp index 85720ad41..e31e526c0 100644 --- a/apps/opencs/view/settings/groupblock.cpp +++ b/apps/opencs/view/settings/groupblock.cpp @@ -19,7 +19,7 @@ int CSVSettings::GroupBlock::build (GroupBlockDef *def) setVisible (def->isVisible); - mBox->setLayout(createLayout (def->widgetOrientation, true)); + mBox->setLayout(createLayout (def->widgetOrientation, def->isZeroMargin)); setObjectName (def->title); mBox->setTitle (def->title); diff --git a/apps/opencs/view/settings/support.hpp b/apps/opencs/view/settings/support.hpp index 1df0dac1e..5d954505c 100644 --- a/apps/opencs/view/settings/support.hpp +++ b/apps/opencs/view/settings/support.hpp @@ -168,11 +168,14 @@ namespace CSVSettings /// generic default value attribute QString defaultValue; - GroupBlockDef (): title(""), widgetOrientation (Orient_Vertical), isVisible (true), isProxy (false), defaultValue ("") + /// shows / hides margins + bool isZeroMargin; + + GroupBlockDef (): title(""), widgetOrientation (Orient_Vertical), isVisible (true), isProxy (false), defaultValue (""), isZeroMargin (true) {} GroupBlockDef (QString blockTitle) - : title (blockTitle), widgetOrientation (Orient_Vertical), isProxy (false), isVisible (true), defaultValue ("") + : title (blockTitle), widgetOrientation (Orient_Vertical), isProxy (false), isVisible (true), defaultValue (""), isZeroMargin (true) {} }; diff --git a/apps/opencs/view/settings/usersettingsdialog.cpp b/apps/opencs/view/settings/usersettingsdialog.cpp index 64b9aacff..947e8cd1b 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" @@ -56,8 +56,8 @@ void CSVSettings::UserSettingsDialog::setWidgetStates () if (sectionSettings.find(pageName) != sectionSettings.end()) { CSMSettings::SettingMap *settings = sectionSettings.value(pageName); - AbstractPage *page = getAbstractPage (i); - page->initializeWidgets(*settings); + AbstractPage &page = getAbstractPage (i); + page.initializeWidgets(*settings); } } } @@ -86,7 +86,7 @@ void CSVSettings::UserSettingsDialog::buildPages() setDockOptions (QMainWindow::AllowNestedDocks); createPage(); - createPage(); + createPage(); } @@ -96,15 +96,15 @@ void CSVSettings::UserSettingsDialog::writeSettings() for (int i = 0; i < mStackedWidget->count(); ++i) { - AbstractPage *page = getAbstractPage (i); - settings [page->objectName()] = page->getSettings(); + AbstractPage &page = getAbstractPage (i); + settings [page.objectName()] = page.getSettings(); } CSMSettings::UserSettings::instance().writeSettings(settings); } -CSVSettings::AbstractPage *CSVSettings::UserSettingsDialog::getAbstractPage (int index) +CSVSettings::AbstractPage &CSVSettings::UserSettingsDialog::getAbstractPage (int index) { - return dynamic_cast(mStackedWidget->widget(index)); + return dynamic_cast (*(mStackedWidget->widget (index))); } 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..3b3fa5b79 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; @@ -38,7 +36,7 @@ namespace CSVSettings { /// return the setting page by name /// performs dynamic cast to AbstractPage * - AbstractPage *getAbstractPage (int index); + AbstractPage &getAbstractPage (int index); void setWidgetStates (); void buildPages(); void writeSettings(); @@ -49,7 +47,7 @@ namespace CSVSettings { { T *page = new T(mStackedWidget); - mStackedWidget->addWidget (dynamic_cast(page)); + mStackedWidget->addWidget (&dynamic_cast(*page)); new QListWidgetItem (page->objectName(), mListWidget); diff --git a/apps/opencs/view/world/datadisplaydelegate.cpp b/apps/opencs/view/world/datadisplaydelegate.cpp new file mode 100755 index 000000000..d838395f6 --- /dev/null +++ b/apps/opencs/view/world/datadisplaydelegate.cpp @@ -0,0 +1,110 @@ +#include "datadisplaydelegate.hpp" +#include +#include + +CSVWorld::DataDisplayDelegate::DataDisplayDelegate(const ValueList &values, + const IconList &icons, + QUndoStack &undoStack, QObject *parent) + : EnumDelegate (values, undoStack, parent), mDisplayMode (Mode_TextOnly), mIcons (icons) + , mIconSize (QSize(16, 16)), mIconLeftOffset(3), mTextLeftOffset(8) +{ + mTextAlignment.setAlignment (Qt::AlignLeft | Qt::AlignVCenter ); + + buildPixmaps(); +} + +void CSVWorld::DataDisplayDelegate::buildPixmaps () +{ + if (mPixmaps.size() > 0) + mPixmaps.clear(); + + IconList::iterator it = mIcons.begin(); + + while (it != mIcons.end()) + { + mPixmaps.push_back (std::make_pair (it->first, it->second.pixmap (mIconSize) ) ); + it++; + } +} + +void CSVWorld::DataDisplayDelegate::setIconSize(const QSize size) +{ + mIconSize = size; + buildPixmaps(); +} + +void CSVWorld::DataDisplayDelegate::setIconLeftOffset(int offset) +{ + mIconLeftOffset = offset; +} + +void CSVWorld::DataDisplayDelegate::setTextLeftOffset(int offset) +{ + mTextLeftOffset = offset; +} + +void CSVWorld::DataDisplayDelegate::paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + painter->save(); + + //default to enum delegate's paint method for text-only conditions + if (mDisplayMode == Mode_TextOnly) + EnumDelegate::paint(painter, option, index); + else + { + unsigned int i = 0; + + for (; i < mValues.size(); ++i) + { + if (mValues.at(i).first == index.data().toInt()) + break; + } + + if (i < mValues.size() ) + paintIcon (painter, option, i); + } + + painter->restore(); +} + +void CSVWorld::DataDisplayDelegate::paintIcon (QPainter *painter, const QStyleOptionViewItem &option, int index) const +{ + //function-level statics + QRect iconRect = option.rect; + QRect textRect = iconRect; + + const QString &text = mValues.at(index).second; + + iconRect.setSize (mIconSize); + iconRect.translate(mIconLeftOffset, (option.rect.height() - iconRect.height())/2); + + if (mDisplayMode == Mode_IconAndText ) + { + textRect.translate (iconRect.width() + mTextLeftOffset, 0 ); + painter->drawText (textRect, text, mTextAlignment); + } + else + iconRect.translate( (option.rect.width() - iconRect.width()) / 2, 0); + + painter->drawPixmap (iconRect, mPixmaps.at(index).second); +} + +CSVWorld::DataDisplayDelegate::~DataDisplayDelegate() +{ + mIcons.clear(); + mPixmaps.clear(); +} + +void CSVWorld::DataDisplayDelegateFactory::add (int enumValue, QString enumName, QString iconFilename) +{ + mIcons.push_back (std::make_pair(enumValue, QIcon(iconFilename))); + EnumDelegateFactory::add(enumValue, enumName); + +} + +CSVWorld::CommandDelegate *CSVWorld::DataDisplayDelegateFactory::makeDelegate (QUndoStack& undoStack, + QObject *parent) const +{ + + return new DataDisplayDelegate (mValues, mIcons, undoStack, parent); +} diff --git a/apps/opencs/view/world/datadisplaydelegate.hpp b/apps/opencs/view/world/datadisplaydelegate.hpp new file mode 100755 index 000000000..d23b86631 --- /dev/null +++ b/apps/opencs/view/world/datadisplaydelegate.hpp @@ -0,0 +1,85 @@ +#ifndef DATADISPLAYDELEGATE_HPP +#define DATADISPLAYDELEGATE_HPP + +#include +#include "enumdelegate.hpp" + +namespace CSVWorld +{ + + + class DataDisplayDelegate : public EnumDelegate + { + public: + + typedef std::vector < std::pair < int, QIcon > > IconList; + typedef std::vector > ValueList; + + protected: + + enum DisplayMode + { + Mode_TextOnly, + Mode_IconOnly, + Mode_IconAndText + }; + + DisplayMode mDisplayMode; + IconList mIcons; + + private: + + std::vector > mPixmaps; + QTextOption mTextAlignment; + QSize mIconSize; + int mIconLeftOffset; + int mTextLeftOffset; + + public: + explicit DataDisplayDelegate (const ValueList & values, + const IconList & icons, + QUndoStack& undoStack, QObject *parent); + + ~DataDisplayDelegate(); + + virtual void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + + /// pass a QSize defining height / width of icon. Default is QSize (16,16). + void setIconSize (const QSize icon); + + /// offset the horizontal position of the icon from the left edge of the cell. Default is 3 pixels. + void setIconLeftOffset (int offset); + + /// offset the horizontal position of the text from the right edge of the icon. Default is 8 pixels. + void setTextLeftOffset (int offset); + + private: + + /// custom paint function for painting the icon. Mode_IconAndText and Mode_Icon only. + void paintIcon (QPainter *painter, const QStyleOptionViewItem &option, int i) const; + + /// rebuild the list of pixmaps from the provided icons (called when icon size is changed) + void buildPixmaps(); + + }; + + class DataDisplayDelegateFactory : public EnumDelegateFactory + { + protected: + + DataDisplayDelegate::IconList mIcons; + + public: + + virtual CommandDelegate *makeDelegate (QUndoStack& undoStack, QObject *parent) const; + ///< The ownership of the returned CommandDelegate is transferred to the caller. + + protected: + + void add (int enumValue,const QString enumName, const QString iconFilename); + + }; + +} + +#endif // DATADISPLAYDELEGATE_HPP 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..4e137e635 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; + mDisplayMode = 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/refidtypedelegate.cpp b/apps/opencs/view/world/refidtypedelegate.cpp new file mode 100755 index 000000000..d89d2cd31 --- /dev/null +++ b/apps/opencs/view/world/refidtypedelegate.cpp @@ -0,0 +1,67 @@ +#include "refidtypedelegate.hpp" +#include "../../model/world/universalid.hpp" + +CSVWorld::RefIdTypeDelegate::RefIdTypeDelegate + (const ValueList &values, const IconList &icons, QUndoStack& undoStack, QObject *parent) + : DataDisplayDelegate (values, icons, undoStack, parent) +{} + +CSVWorld::RefIdTypeDelegateFactory::RefIdTypeDelegateFactory() +{ + UidTypeList uIdList = buildUidTypeList(); + + for (UidTypeList::const_iterator it = uIdList.begin(); it != uIdList.end(); it++) + { + int i = it->first; + DataDisplayDelegateFactory::add (i, QString::fromStdString(CSMWorld::UniversalId(it->first, "").getTypeName()), it->second); + } +} + +CSVWorld::CommandDelegate *CSVWorld::RefIdTypeDelegateFactory::makeDelegate (QUndoStack& undoStack, + QObject *parent) const +{ + return new RefIdTypeDelegate (mValues, mIcons, undoStack, parent); +} + +CSVWorld::RefIdTypeDelegateFactory::UidTypeList CSVWorld::RefIdTypeDelegateFactory::buildUidTypeList() const +{ + UidTypeList list; + + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_Activator, ":./activator.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_Potion, ":./potion.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_Apparatus, ":./apparatus.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_Armor, ":./armor.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_Book, ":./book.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_Clothing, ":./clothing.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_Container, ":./container.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_Creature, ":./creature.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_Door, ":./door.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_Ingredient, ":./ingredient.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_CreatureLevelledList, ":./creature.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_ItemLevelledList, ":./item.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_Light, ":./light.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_Lockpick, ":./lockpick.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_Miscellaneous, ":./misc.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_Npc, ":./npc.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_Probe, ":./probe.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_Repair, ":./repair.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_Static, ":./static.png")); + list.push_back (std::make_pair (CSMWorld::UniversalId::Type_Weapon, ":./weapon.png")); + + return list; +} + +void CSVWorld::RefIdTypeDelegate::updateEditorSetting (const QString &settingName, const QString &settingValue) +{ + if (settingName == "Referenceable ID Type Display") + { + if (settingValue == "Icon and Text") + mDisplayMode = Mode_IconAndText; + + else if (settingValue == "Icon Only") + mDisplayMode = Mode_IconOnly; + + else if (settingValue == "Text Only") + mDisplayMode = Mode_TextOnly; + } +} diff --git a/apps/opencs/view/world/refidtypedelegate.hpp b/apps/opencs/view/world/refidtypedelegate.hpp new file mode 100755 index 000000000..0b6b8e079 --- /dev/null +++ b/apps/opencs/view/world/refidtypedelegate.hpp @@ -0,0 +1,37 @@ +#ifndef REFIDTYPEDELEGATE_HPP +#define REFIDTYPEDELEGATE_HPP + +#include "enumdelegate.hpp" +#include "util.hpp" +#include "../../model/world/universalid.hpp" +#include "datadisplaydelegate.hpp" + +namespace CSVWorld +{ + class RefIdTypeDelegate : public DataDisplayDelegate + { + public: + RefIdTypeDelegate (const ValueList &mValues, const IconList &icons, QUndoStack& undoStack, QObject *parent); + + void updateEditorSetting (const QString &settingName, const QString &settingValue); + + }; + + class RefIdTypeDelegateFactory : public DataDisplayDelegateFactory + { + + typedef std::vector < std::pair > UidTypeList; + + public: + RefIdTypeDelegateFactory(); + + virtual CommandDelegate *makeDelegate (QUndoStack& undoStack, QObject *parent) const; + ///< The ownership of the returned CommandDelegate is transferred to the caller. + + private: + UidTypeList buildUidTypeList () const; + + }; +} + +#endif // REFIDTYPEDELEGATE_HPP diff --git a/apps/opencs/view/world/refrecordtypedelegate.cpp b/apps/opencs/view/world/refrecordtypedelegate.cpp new file mode 100644 index 000000000..2bcb7ca50 --- /dev/null +++ b/apps/opencs/view/world/refrecordtypedelegate.cpp @@ -0,0 +1,25 @@ +#include "refrecordtypedelegate.hpp" +#include "../../model/world/universalid.hpp" + +CSVWorld::RefRecordTypeDelegate::RefRecordTypeDelegate + (const std::vector > &values, QUndoStack& undoStack, QObject *parent) + : EnumDelegate (values, undoStack, parent) +{} + +CSVWorld::RefRecordTypeDelegateFactory::RefRecordTypeDelegateFactory() +{ + unsigned int argSize = CSMWorld::UniversalId::getIdArgSize(); + + for (unsigned int i = 0; i < argSize; i++) + { + std::pair idPair = CSMWorld::UniversalId::getIdArgPair(i); + + mValues.push_back (std::pair(idPair.first, QString::fromUtf8(idPair.second))); + } +} + +CSVWorld::CommandDelegate *CSVWorld::RefRecordTypeDelegateFactory::makeDelegate (QUndoStack& undoStack, + QObject *parent) const +{ + return new RefRecordTypeDelegate (mValues, undoStack, parent); +} diff --git a/apps/opencs/view/world/refrecordtypedelegate.hpp b/apps/opencs/view/world/refrecordtypedelegate.hpp new file mode 100644 index 000000000..baec2cc2e --- /dev/null +++ b/apps/opencs/view/world/refrecordtypedelegate.hpp @@ -0,0 +1,58 @@ +#ifndef REFRECORDTYPEDELEGATE_HPP +#define REFRECORDTYPEDELEGATE_HPP + +#include "enumdelegate.hpp" +#include "util.hpp" + +namespace CSVWorld +{ + class RefRecordTypeDelegate : public EnumDelegate + { + public: + RefRecordTypeDelegate (const std::vector > &mValues, QUndoStack& undoStack, QObject *parent); + }; + + class RefRecordTypeDelegateFactory : public CommandDelegateFactory + { + + std::vector > mValues; + + public: + RefRecordTypeDelegateFactory(); + + virtual CommandDelegate *makeDelegate (QUndoStack& undoStack, QObject *parent) const; + ///< The ownership of the returned CommandDelegate is transferred to the caller. + }; +} +/* + class VarTypeDelegate : public EnumDelegate + { + private: + + virtual void addCommands (QAbstractItemModel *model, + const QModelIndex& index, int type) const; + + public: + + VarTypeDelegate (const std::vector >& values, + QUndoStack& undoStack, QObject *parent); + }; + + class VarTypeDelegateFactory : public CommandDelegateFactory + { + std::vector > mValues; + + public: + + VarTypeDelegateFactory (ESM::VarType type0 = ESM::VT_Unknown, + ESM::VarType type1 = ESM::VT_Unknown, ESM::VarType type2 = ESM::VT_Unknown, + ESM::VarType type3 = ESM::VT_Unknown); + + virtual CommandDelegate *makeDelegate (QUndoStack& undoStack, QObject *parent) const; + ///< The ownership of the returned CommandDelegate is transferred to the caller. + + void add (ESM::VarType type); + }; +*/ + +#endif // REFRECORDTYPEDELEGATE_HPP diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 00a302191..f188adfaf 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,17 @@ void CSVWorld::Table::updateEditorSetting (const QString &settingName, const QSt { if (settingName == "Record Status Display") { - dynamic_cast (*itemDelegateForColumn(1)).updateEditorSetting (settingName, settingValue); + RecordStatusDelegate &rsDelegate = dynamic_cast (*itemDelegateForColumn(1)); + + 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)); + + 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/activator.png b/files/opencs/activator.png new file mode 100755 index 000000000..0446af22c Binary files /dev/null and b/files/opencs/activator.png differ diff --git a/files/opencs/apparatus.png b/files/opencs/apparatus.png new file mode 100755 index 000000000..3cef537e1 Binary files /dev/null and b/files/opencs/apparatus.png differ diff --git a/files/opencs/armor.png b/files/opencs/armor.png new file mode 100755 index 000000000..fc534c7d1 Binary files /dev/null and b/files/opencs/armor.png differ diff --git a/files/opencs/book.png b/files/opencs/book.png new file mode 100755 index 000000000..3afa9e8aa Binary files /dev/null and b/files/opencs/book.png differ diff --git a/files/opencs/clothing.png b/files/opencs/clothing.png new file mode 100755 index 000000000..88c9b6ab8 Binary files /dev/null and b/files/opencs/clothing.png differ diff --git a/files/opencs/container.png b/files/opencs/container.png new file mode 100755 index 000000000..2a6ed01eb Binary files /dev/null and b/files/opencs/container.png differ diff --git a/files/opencs/creature.png b/files/opencs/creature.png new file mode 100755 index 000000000..99cf9c87c Binary files /dev/null and b/files/opencs/creature.png differ diff --git a/files/opencs/door.png b/files/opencs/door.png new file mode 100755 index 000000000..aa48858ef Binary files /dev/null and b/files/opencs/door.png differ diff --git a/files/opencs/ingredient.png b/files/opencs/ingredient.png new file mode 100755 index 000000000..6b36d008d Binary files /dev/null and b/files/opencs/ingredient.png differ diff --git a/files/opencs/leveled-creature.png b/files/opencs/leveled-creature.png new file mode 100755 index 000000000..ad4a7c6f8 Binary files /dev/null and b/files/opencs/leveled-creature.png differ diff --git a/files/opencs/leveled-item.png b/files/opencs/leveled-item.png new file mode 100755 index 000000000..7b8e68e60 Binary files /dev/null and b/files/opencs/leveled-item.png differ diff --git a/files/opencs/light.png b/files/opencs/light.png new file mode 100755 index 000000000..c606fcd98 Binary files /dev/null and b/files/opencs/light.png differ diff --git a/files/opencs/lockpick.png b/files/opencs/lockpick.png new file mode 100755 index 000000000..d9bd27f5e Binary files /dev/null and b/files/opencs/lockpick.png differ diff --git a/files/opencs/miscellaneous.png b/files/opencs/miscellaneous.png new file mode 100755 index 000000000..744bcd9db Binary files /dev/null and b/files/opencs/miscellaneous.png differ diff --git a/files/opencs/npc.png b/files/opencs/npc.png new file mode 100755 index 000000000..7a07f26df Binary files /dev/null and b/files/opencs/npc.png differ diff --git a/files/opencs/potion.png b/files/opencs/potion.png new file mode 100755 index 000000000..678f61fbf Binary files /dev/null and b/files/opencs/potion.png differ diff --git a/files/opencs/probe.png b/files/opencs/probe.png new file mode 100755 index 000000000..01536186d Binary files /dev/null and b/files/opencs/probe.png differ diff --git a/files/opencs/repair.png b/files/opencs/repair.png new file mode 100755 index 000000000..6cf1c0aac Binary files /dev/null and b/files/opencs/repair.png differ 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 diff --git a/files/opencs/static.png b/files/opencs/static.png new file mode 100755 index 000000000..b53be12d9 Binary files /dev/null and b/files/opencs/static.png differ diff --git a/files/opencs/weapon.png b/files/opencs/weapon.png new file mode 100755 index 000000000..3d4b53466 Binary files /dev/null and b/files/opencs/weapon.png differ