forked from mirror/openmw-tes3mp
Final details implemented
Png icons, alignments fixed.
This commit is contained in:
parent
5a40594b0d
commit
35fb9b669a
7 changed files with 168 additions and 4 deletions
|
@ -61,7 +61,7 @@ opencs_units (view/world
|
||||||
)
|
)
|
||||||
|
|
||||||
opencs_units_noqt (view/world
|
opencs_units_noqt (view/world
|
||||||
dialoguesubview util subviews enumdelegate vartypedelegate scripthighlighter
|
dialoguesubview util subviews enumdelegate vartypedelegate scripthighlighter recordstatusdelegate
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,8 @@ namespace CSMWorld
|
||||||
Display_ArmorType,
|
Display_ArmorType,
|
||||||
Display_ClothingType,
|
Display_ClothingType,
|
||||||
Display_CreatureType,
|
Display_CreatureType,
|
||||||
Display_WeaponType
|
Display_WeaponType,
|
||||||
|
Display_RecordState
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string mTitle;
|
std::string mTitle;
|
||||||
|
|
|
@ -53,7 +53,7 @@ namespace CSMWorld
|
||||||
template<typename ESXRecordT>
|
template<typename ESXRecordT>
|
||||||
struct RecordStateColumn : public Column<ESXRecordT>
|
struct RecordStateColumn : public Column<ESXRecordT>
|
||||||
{
|
{
|
||||||
RecordStateColumn() : Column<ESXRecordT> ("*", ColumnBase::Display_Integer) {}
|
RecordStateColumn() : Column<ESXRecordT> ("*", ColumnBase::Display_RecordState) {}
|
||||||
|
|
||||||
virtual QVariant get (const Record<ESXRecordT>& record) const
|
virtual QVariant get (const Record<ESXRecordT>& record) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "../world/util.hpp"
|
#include "../world/util.hpp"
|
||||||
#include "../world/enumdelegate.hpp"
|
#include "../world/enumdelegate.hpp"
|
||||||
#include "../world/vartypedelegate.hpp"
|
#include "../world/vartypedelegate.hpp"
|
||||||
|
#include "../world/recordstatusdelegate.hpp"
|
||||||
|
|
||||||
#include "view.hpp"
|
#include "view.hpp"
|
||||||
|
|
||||||
|
@ -117,6 +118,9 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
|
||||||
|
|
||||||
mDelegateFactories->add (CSMWorld::ColumnBase::Display_WeaponType,
|
mDelegateFactories->add (CSMWorld::ColumnBase::Display_WeaponType,
|
||||||
new CSVWorld::EnumDelegateFactory (sWeaponTypes));
|
new CSVWorld::EnumDelegateFactory (sWeaponTypes));
|
||||||
|
|
||||||
|
mDelegateFactories->add (CSMWorld::ColumnBase::Display_RecordState,
|
||||||
|
new CSVWorld::RecordStatusDelegateFactory() );
|
||||||
}
|
}
|
||||||
|
|
||||||
CSVDoc::ViewManager::~ViewManager()
|
CSVDoc::ViewManager::~ViewManager()
|
||||||
|
|
111
apps/opencs/view/world/recordstatusdelegate.cpp
Normal file
111
apps/opencs/view/world/recordstatusdelegate.cpp
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
#include "recordstatusdelegate.hpp"
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QFont>
|
||||||
|
#include <QUndoStack>
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
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");
|
||||||
|
mIconSize = 16;
|
||||||
|
|
||||||
|
//Offset values are most likely device-dependent.
|
||||||
|
//Need to replace with device-independent references.
|
||||||
|
mTextTopOffset = -1;
|
||||||
|
mTextLeftOffset = 3;
|
||||||
|
mIconTopOffset = -3;
|
||||||
|
mIconLeftOffset = 0;
|
||||||
|
|
||||||
|
mStatusDisplay = 0; //icons and text by default
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::RecordStatusDelegate::paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
painter->save();
|
||||||
|
|
||||||
|
QFont font = QApplication::font();
|
||||||
|
font.setPointSize(10);
|
||||||
|
|
||||||
|
QFontMetrics fm(font);
|
||||||
|
|
||||||
|
QString text = "";
|
||||||
|
QIcon *icon = 0;
|
||||||
|
|
||||||
|
switch (index.data().toInt())
|
||||||
|
{
|
||||||
|
case 0: // State_BaseOnly
|
||||||
|
text = "base";
|
||||||
|
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);
|
||||||
|
textRect.setLeft (iconRect.right() + (mIconSize/4) * 3);
|
||||||
|
textRect.setRight (textRect.left() + fm.width(text));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
textRect.setLeft (textRect.left() + mTextLeftOffset );
|
||||||
|
|
||||||
|
textRect.setTop (textRect.top() + ((option.rect.height() - fm.height()) / 2) + mTextTopOffset);
|
||||||
|
|
||||||
|
if (mStatusDisplay == 0 || mStatusDisplay == 1)
|
||||||
|
{
|
||||||
|
if (icon)
|
||||||
|
painter->drawPixmap(iconRect.center(),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(font);
|
||||||
|
painter->drawText(textRect,text);
|
||||||
|
}
|
||||||
|
|
||||||
|
painter->restore();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize CSVWorld::RecordStatusDelegate::sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
return QSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
CSVWorld::CommandDelegate *CSVWorld::RecordStatusDelegateFactory::makeDelegate (QUndoStack& undoStack,
|
||||||
|
QObject *parent) const
|
||||||
|
{
|
||||||
|
return new RecordStatusDelegate (undoStack, parent);
|
||||||
|
}
|
45
apps/opencs/view/world/recordstatusdelegate.hpp
Normal file
45
apps/opencs/view/world/recordstatusdelegate.hpp
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#ifndef RECORDSTATUSDELEGATE_H
|
||||||
|
#define RECORDSTATUSDELEGATE_H
|
||||||
|
|
||||||
|
#include "util.hpp"
|
||||||
|
|
||||||
|
class QIcon;
|
||||||
|
|
||||||
|
namespace CSVWorld
|
||||||
|
{
|
||||||
|
class RecordStatusDelegate : public CommandDelegate
|
||||||
|
{
|
||||||
|
|
||||||
|
QIcon *mModifiedIcon;
|
||||||
|
QIcon *mAddedIcon;
|
||||||
|
QIcon *mDeletedIcon;
|
||||||
|
int mStatusDisplay;
|
||||||
|
|
||||||
|
int mIconSize;
|
||||||
|
int mIconTopOffset;
|
||||||
|
int mIconLeftOffset;
|
||||||
|
int mTextTopOffset;
|
||||||
|
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;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class RecordStatusDelegateFactory : public CommandDelegateFactory
|
||||||
|
{
|
||||||
|
//std::vector<std::pair<int, QString> > mValues;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual CommandDelegate *makeDelegate (QUndoStack& undoStack, QObject *parent) const;
|
||||||
|
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif // RECORDSTATUSDELEGATE_H
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/">
|
<qresource prefix="/">
|
||||||
<file>opencs.png</file>
|
<file>opencs.png</file>
|
||||||
|
<file>added.png</file>
|
||||||
|
<file>modified.png</file>
|
||||||
|
<file>removed.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
Loading…
Reference in a new issue