mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-15 07:06:44 +00:00
Cell formatting and code optimization changes
This commit is contained in:
parent
94db7cdcfe
commit
1d93cf09bc
2 changed files with 29 additions and 32 deletions
|
@ -1,11 +1,8 @@
|
||||||
#include "recordstatusdelegate.hpp"
|
#include "recordstatusdelegate.hpp"
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QFont>
|
|
||||||
#include <QUndoStack>
|
#include <QUndoStack>
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
CSVWorld::RecordStatusDelegate::RecordStatusDelegate(QUndoStack &undoStack, QObject *parent)
|
CSVWorld::RecordStatusDelegate::RecordStatusDelegate(QUndoStack &undoStack, QObject *parent)
|
||||||
: CommandDelegate (undoStack, parent)
|
: CommandDelegate (undoStack, parent)
|
||||||
{
|
{
|
||||||
|
@ -16,23 +13,23 @@ CSVWorld::RecordStatusDelegate::RecordStatusDelegate(QUndoStack &undoStack, QObj
|
||||||
|
|
||||||
//Offset values are most likely device-dependent.
|
//Offset values are most likely device-dependent.
|
||||||
//Need to replace with device-independent references.
|
//Need to replace with device-independent references.
|
||||||
mTextTopOffset = -1;
|
|
||||||
mTextLeftOffset = 3;
|
mTextLeftOffset = 3;
|
||||||
mIconTopOffset = -3;
|
mIconTopOffset = -3;
|
||||||
mIconLeftOffset = 0;
|
|
||||||
|
|
||||||
mStatusDisplay = 0; //icons and text by default
|
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
|
void CSVWorld::RecordStatusDelegate::paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
QFont font = QApplication::font();
|
|
||||||
font.setPointSize(10);
|
|
||||||
|
|
||||||
QFontMetrics fm(font);
|
|
||||||
|
|
||||||
QString text = "";
|
QString text = "";
|
||||||
QIcon *icon = 0;
|
QIcon *icon = 0;
|
||||||
|
|
||||||
|
@ -73,30 +70,23 @@ void CSVWorld::RecordStatusDelegate::paint (QPainter *painter, const QStyleOptio
|
||||||
|
|
||||||
if (mStatusDisplay == 0 && (icon) )
|
if (mStatusDisplay == 0 && (icon) )
|
||||||
{
|
{
|
||||||
iconRect.setRight (iconRect.left() + mIconSize);
|
iconRect.setRight (iconRect.left() + mIconSize*2);
|
||||||
textRect.setLeft (iconRect.right() + (mIconSize/4) * 3);
|
textRect.setLeft (iconRect.right() + mTextLeftOffset *2);
|
||||||
textRect.setRight (textRect.left() + fm.width(text));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
textRect.setLeft (textRect.left() + mTextLeftOffset );
|
textRect.setLeft (textRect.left() + mTextLeftOffset );
|
||||||
|
|
||||||
textRect.setTop (textRect.top() + ((option.rect.height() - fm.height()) / 2) + mTextTopOffset);
|
if ( (mStatusDisplay == 0 || mStatusDisplay == 1) && (icon) )
|
||||||
|
|
||||||
if (mStatusDisplay == 0 || mStatusDisplay == 1)
|
|
||||||
{
|
|
||||||
if (icon)
|
|
||||||
painter->drawPixmap(iconRect.center(),icon->pixmap(mIconSize, mIconSize));
|
painter->drawPixmap(iconRect.center(),icon->pixmap(mIconSize, mIconSize));
|
||||||
}
|
|
||||||
|
|
||||||
// icon + text or text only, or force text if no icon exists for status
|
// icon + text or text only, or force text if no icon exists for status
|
||||||
if (mStatusDisplay == 0 || mStatusDisplay == 2 || !(icon) )
|
if (mStatusDisplay == 0 || mStatusDisplay == 2 || !(icon) )
|
||||||
{
|
{
|
||||||
painter->setFont(font);
|
painter->setFont(mFont);
|
||||||
painter->drawText(textRect,text);
|
painter->drawText(textRect, text, mTextAlignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize CSVWorld::RecordStatusDelegate::sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const
|
QSize CSVWorld::RecordStatusDelegate::sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
|
|
@ -2,24 +2,31 @@
|
||||||
#define RECORDSTATUSDELEGATE_H
|
#define RECORDSTATUSDELEGATE_H
|
||||||
|
|
||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
|
#include <QTextOption>
|
||||||
|
#include <QFont>
|
||||||
|
|
||||||
class QIcon;
|
class QIcon;
|
||||||
|
class QFont;
|
||||||
|
class QFontMetrics;
|
||||||
|
|
||||||
namespace CSVWorld
|
namespace CSVWorld
|
||||||
{
|
{
|
||||||
class RecordStatusDelegate : public CommandDelegate
|
class RecordStatusDelegate : public CommandDelegate
|
||||||
{
|
{
|
||||||
|
QFont mFont;
|
||||||
|
QFontMetrics *mFontMetrics;
|
||||||
|
|
||||||
QIcon *mModifiedIcon;
|
QTextOption mTextAlignment;
|
||||||
QIcon *mAddedIcon;
|
|
||||||
QIcon *mDeletedIcon;
|
|
||||||
int mStatusDisplay;
|
|
||||||
|
|
||||||
int mIconSize;
|
QIcon *mModifiedIcon;
|
||||||
int mIconTopOffset;
|
QIcon *mAddedIcon;
|
||||||
int mIconLeftOffset;
|
QIcon *mDeletedIcon;
|
||||||
int mTextTopOffset;
|
|
||||||
int mTextLeftOffset;
|
int mStatusDisplay;
|
||||||
|
|
||||||
|
int mIconSize;
|
||||||
|
int mIconTopOffset;
|
||||||
|
int mTextLeftOffset;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit RecordStatusDelegate(QUndoStack& undoStack, QObject *parent = 0);
|
explicit RecordStatusDelegate(QUndoStack& undoStack, QObject *parent = 0);
|
||||||
|
|
Loading…
Reference in a new issue