From f56eff04ef4d23b62a6e095eca5d4b9f2b52e023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 1 Dec 2013 16:34:51 +0100 Subject: Fix (hopefully) library dependency resolution. Installing libs is now enabled, hardcoded. Enable -Wall for all builds. Fix many warnings and latent bugs. --- gui/dialogs/CopyInstanceDialog.cpp | 2 +- gui/dialogs/EditNotesDialog.cpp | 4 +- gui/dialogs/InstanceSettings.cpp | 2 +- gui/dialogs/LegacyModEditDialog.cpp | 2 +- gui/dialogs/OneSixModEditDialog.cpp | 2 +- gui/widgets/InstanceDelegate.cpp | 176 +++++++++++++++++++----------------- 6 files changed, 98 insertions(+), 90 deletions(-) (limited to 'gui') diff --git a/gui/dialogs/CopyInstanceDialog.cpp b/gui/dialogs/CopyInstanceDialog.cpp index 4d588a1e..9d7ac30c 100644 --- a/gui/dialogs/CopyInstanceDialog.cpp +++ b/gui/dialogs/CopyInstanceDialog.cpp @@ -33,7 +33,7 @@ #include "logic/BaseInstance.h" CopyInstanceDialog::CopyInstanceDialog(BaseInstance *original, QWidget *parent) - : m_original(original), QDialog(parent), ui(new Ui::CopyInstanceDialog) + :QDialog(parent), ui(new Ui::CopyInstanceDialog), m_original(original) { MultiMCPlatform::fixWM_CLASS(this); ui->setupUi(this); diff --git a/gui/dialogs/EditNotesDialog.cpp b/gui/dialogs/EditNotesDialog.cpp index cd52e694..a265a4d0 100644 --- a/gui/dialogs/EditNotesDialog.cpp +++ b/gui/dialogs/EditNotesDialog.cpp @@ -21,8 +21,8 @@ #include EditNotesDialog::EditNotesDialog(QString notes, QString name, QWidget *parent) - : m_instance_notes(notes), m_instance_name(name), QDialog(parent), - ui(new Ui::EditNotesDialog) + : QDialog(parent), ui(new Ui::EditNotesDialog), m_instance_name(name), + m_instance_notes(notes) { MultiMCPlatform::fixWM_CLASS(this); ui->setupUi(this); diff --git a/gui/dialogs/InstanceSettings.cpp b/gui/dialogs/InstanceSettings.cpp index f059047f..bc6b266a 100644 --- a/gui/dialogs/InstanceSettings.cpp +++ b/gui/dialogs/InstanceSettings.cpp @@ -32,7 +32,7 @@ #include InstanceSettings::InstanceSettings(SettingsObject *obj, QWidget *parent) - : m_obj(obj), QDialog(parent), ui(new Ui::InstanceSettings) + : QDialog(parent), ui(new Ui::InstanceSettings), m_obj(obj) { MultiMCPlatform::fixWM_CLASS(this); ui->setupUi(this); diff --git a/gui/dialogs/LegacyModEditDialog.cpp b/gui/dialogs/LegacyModEditDialog.cpp index 25a1c616..66d53ee1 100644 --- a/gui/dialogs/LegacyModEditDialog.cpp +++ b/gui/dialogs/LegacyModEditDialog.cpp @@ -31,7 +31,7 @@ #include LegacyModEditDialog::LegacyModEditDialog(LegacyInstance *inst, QWidget *parent) - : m_inst(inst), QDialog(parent), ui(new Ui::LegacyModEditDialog) + : QDialog(parent), ui(new Ui::LegacyModEditDialog), m_inst(inst) { MultiMCPlatform::fixWM_CLASS(this); ui->setupUi(this); diff --git a/gui/dialogs/OneSixModEditDialog.cpp b/gui/dialogs/OneSixModEditDialog.cpp index dea1b86b..51ea2d19 100644 --- a/gui/dialogs/OneSixModEditDialog.cpp +++ b/gui/dialogs/OneSixModEditDialog.cpp @@ -40,7 +40,7 @@ #include "logic/ForgeInstaller.h" OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent) - : m_inst(inst), QDialog(parent), ui(new Ui::OneSixModEditDialog) + : QDialog(parent), ui(new Ui::OneSixModEditDialog), m_inst(inst) { MultiMCPlatform::fixWM_CLASS(this); ui->setupUi(this); diff --git a/gui/widgets/InstanceDelegate.cpp b/gui/widgets/InstanceDelegate.cpp index 487fed61..5020b8b6 100644 --- a/gui/widgets/InstanceDelegate.cpp +++ b/gui/widgets/InstanceDelegate.cpp @@ -21,45 +21,45 @@ #include // Origin: Qt -static void viewItemTextLayout ( QTextLayout &textLayout, int lineWidth, qreal &height, qreal &widthUsed ) +static void viewItemTextLayout(QTextLayout &textLayout, int lineWidth, qreal &height, + qreal &widthUsed) { height = 0; widthUsed = 0; textLayout.beginLayout(); QString str = textLayout.text(); - while ( true ) + while (true) { QTextLine line = textLayout.createLine(); - if ( !line.isValid() ) + if (!line.isValid()) break; - if(line.textLength() == 0) + if (line.textLength() == 0) break; - line.setLineWidth ( lineWidth ); - line.setPosition ( QPointF ( 0, height ) ); + line.setLineWidth(lineWidth); + line.setPosition(QPointF(0, height)); height += line.height(); - widthUsed = qMax ( widthUsed, line.naturalTextWidth() ); + widthUsed = qMax(widthUsed, line.naturalTextWidth()); } textLayout.endLayout(); } -#define QFIXED_MAX (INT_MAX/256) +#define QFIXED_MAX (INT_MAX / 256) -ListViewDelegate::ListViewDelegate ( QObject* parent ) : QStyledItemDelegate ( parent ) +ListViewDelegate::ListViewDelegate(QObject *parent) : QStyledItemDelegate(parent) { - } -void drawSelectionRect(QPainter *painter, const QStyleOptionViewItemV4 &option, const QRect &rect) +void drawSelectionRect(QPainter *painter, const QStyleOptionViewItemV4 &option, + const QRect &rect) { if ((option.state & QStyle::State_Selected)) - painter->fillRect ( rect, option.palette.brush ( QPalette::Highlight ) ); + painter->fillRect(rect, option.palette.brush(QPalette::Highlight)); else { QColor backgroundColor = option.palette.color(QPalette::Background); backgroundColor.setAlpha(160); - painter->fillRect ( rect, QBrush(backgroundColor) ); + painter->fillRect(rect, QBrush(backgroundColor)); } - } void drawFocusRect(QPainter *painter, const QStyleOptionViewItemV4 &option, const QRect &rect) @@ -67,11 +67,12 @@ void drawFocusRect(QPainter *painter, const QStyleOptionViewItemV4 &option, cons if (!(option.state & QStyle::State_HasFocus)) return; QStyleOptionFocusRect opt; - opt.direction = option.direction; - opt.fontMetrics = option.fontMetrics; - opt.palette = option.palette; - opt.rect = rect; - //opt.state = option.state | QStyle::State_KeyboardFocusChange | QStyle::State_Item; + opt.direction = option.direction; + opt.fontMetrics = option.fontMetrics; + opt.palette = option.palette; + opt.rect = rect; + // opt.state = option.state | QStyle::State_KeyboardFocusChange | + // QStyle::State_Item; auto col = option.state & QStyle::State_Selected ? QPalette::Highlight : QPalette::Base; opt.backgroundColor = option.palette.color(col); // Apparently some widget styles expect this hint to not be set @@ -84,29 +85,31 @@ void drawFocusRect(QPainter *painter, const QStyleOptionViewItemV4 &option, cons painter->setRenderHint(QPainter::Antialiasing); } -static QSize viewItemTextSize ( const QStyleOptionViewItemV4 *option ) +static QSize viewItemTextSize(const QStyleOptionViewItemV4 *option) { QStyle *style = option->widget ? option->widget->style() : QApplication::style(); QTextOption textOption; - textOption.setWrapMode ( QTextOption::WrapAtWordBoundaryOrAnywhere ); + textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); QTextLayout textLayout; - textLayout.setTextOption ( textOption ); - textLayout.setFont ( option->font ); - textLayout.setText ( option->text ); - const int textMargin = style->pixelMetric ( QStyle::PM_FocusFrameHMargin, option, option->widget ) + 1; - QRect bounds ( 0,0,100 - 2*textMargin,600 ); + textLayout.setTextOption(textOption); + textLayout.setFont(option->font); + textLayout.setText(option->text); + const int textMargin = + style->pixelMetric(QStyle::PM_FocusFrameHMargin, option, option->widget) + 1; + QRect bounds(0, 0, 100 - 2 * textMargin, 600); qreal height = 0, widthUsed = 0; - viewItemTextLayout ( textLayout, bounds.width(), height, widthUsed ); - const QSize size ( qCeil ( widthUsed ), qCeil ( height ) ); - return QSize ( size.width() + 2 * textMargin, size.height() ); + viewItemTextLayout(textLayout, bounds.width(), height, widthUsed); + const QSize size(qCeil(widthUsed), qCeil(height)); + return QSize(size.width() + 2 * textMargin, size.height()); } -void ListViewDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const +void ListViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const { QStyleOptionViewItemV4 opt = option; - initStyleOption ( &opt, index ); + initStyleOption(&opt, index); painter->save(); - painter->setClipRect ( opt.rect ); + painter->setClipRect(opt.rect); opt.features |= QStyleOptionViewItem::WrapText; opt.text = index.data().toString(); @@ -115,26 +118,27 @@ void ListViewDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& op QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); - //const int iconSize = style->pixelMetric(QStyle::PM_IconViewIconSize); + // const int iconSize = style->pixelMetric(QStyle::PM_IconViewIconSize); const int iconSize = 48; QRect iconbox = opt.rect; - const int textMargin = style->pixelMetric ( QStyle::PM_FocusFrameHMargin, 0, opt.widget ) + 1; + const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, opt.widget) + 1; QRect textRect = opt.rect; QRect textHighlightRect = textRect; // clip the decoration on top, remove width padding - textRect.adjust ( textMargin,iconSize + textMargin + 5,-textMargin,0 ); - - textHighlightRect.adjust ( 0,iconSize + 5,0,0 ); + textRect.adjust(textMargin, iconSize + textMargin + 5, -textMargin, 0); + + textHighlightRect.adjust(0, iconSize + 5, 0, 0); // draw background { - QSize textSize = viewItemTextSize ( &opt ); + // FIXME: unused + // QSize textSize = viewItemTextSize ( &opt ); QPalette::ColorGroup cg; QStyleOptionViewItemV4 opt2(opt); - - if((opt.widget && opt.widget->isEnabled()) || (opt.state & QStyle::State_Enabled)) + + if ((opt.widget && opt.widget->isEnabled()) || (opt.state & QStyle::State_Enabled)) { - if(! ( opt.state & QStyle::State_Active )) + if (!(opt.state & QStyle::State_Active)) cg = QPalette::Inactive; else cg = QPalette::Normal; @@ -144,31 +148,33 @@ void ListViewDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& op cg = QPalette::Disabled; } opt2.palette.setCurrentColorGroup(cg); - + // fill in background, if any - if ( opt.backgroundBrush.style() != Qt::NoBrush ) + if (opt.backgroundBrush.style() != Qt::NoBrush) { QPointF oldBO = painter->brushOrigin(); - painter->setBrushOrigin ( opt.rect.topLeft() ); - painter->fillRect ( opt.rect, opt.backgroundBrush ); - painter->setBrushOrigin ( oldBO ); + painter->setBrushOrigin(opt.rect.topLeft()); + painter->fillRect(opt.rect, opt.backgroundBrush); + painter->setBrushOrigin(oldBO); } - - if ( opt.showDecorationSelected ) + + if (opt.showDecorationSelected) { - drawSelectionRect(painter,opt2, opt.rect); - drawFocusRect(painter,opt2, opt.rect); - //painter->fillRect ( opt.rect, opt.palette.brush ( cg, QPalette::Highlight ) ); + drawSelectionRect(painter, opt2, opt.rect); + drawFocusRect(painter, opt2, opt.rect); + // painter->fillRect ( opt.rect, opt.palette.brush ( cg, QPalette::Highlight ) ); } else { - - //if ( opt.state & QStyle::State_Selected ) + + // if ( opt.state & QStyle::State_Selected ) { - //QRect textRect = subElementRect ( QStyle::SE_ItemViewItemText, opt, opt.widget ); - //painter->fillRect ( textHighlightRect, opt.palette.brush ( cg, QPalette::Highlight ) ); - drawSelectionRect(painter,opt2, textHighlightRect); - drawFocusRect(painter,opt2, textHighlightRect); + // QRect textRect = subElementRect ( QStyle::SE_ItemViewItemText, opt, + // opt.widget ); + // painter->fillRect ( textHighlightRect, opt.palette.brush ( cg, + // QPalette::Highlight ) ); + drawSelectionRect(painter, opt2, textHighlightRect); + drawFocusRect(painter, opt2, textHighlightRect); } } } @@ -176,71 +182,73 @@ void ListViewDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& op // draw the icon { QIcon::Mode mode = QIcon::Normal; - if ( ! ( opt.state & QStyle::State_Enabled ) ) + if (!(opt.state & QStyle::State_Enabled)) mode = QIcon::Disabled; - else if ( opt.state & QStyle::State_Selected ) + else if (opt.state & QStyle::State_Selected) mode = QIcon::Selected; QIcon::State state = opt.state & QStyle::State_Open ? QIcon::On : QIcon::Off; - iconbox.setHeight ( iconSize ); - opt.icon.paint ( painter, iconbox, Qt::AlignCenter, mode, state ); + iconbox.setHeight(iconSize); + opt.icon.paint(painter, iconbox, Qt::AlignCenter, mode, state); } // set the text colors - QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; - if ( cg == QPalette::Normal && ! ( opt.state & QStyle::State_Active ) ) + QPalette::ColorGroup cg = + opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; + if (cg == QPalette::Normal && !(opt.state & QStyle::State_Active)) cg = QPalette::Inactive; - if ( opt.state & QStyle::State_Selected ) + if (opt.state & QStyle::State_Selected) { - painter->setPen ( opt.palette.color ( cg, QPalette::HighlightedText ) ); + painter->setPen(opt.palette.color(cg, QPalette::HighlightedText)); } else { - painter->setPen ( opt.palette.color ( cg, QPalette::Text ) ); + painter->setPen(opt.palette.color(cg, QPalette::Text)); } // draw the text QTextOption textOption; - textOption.setWrapMode ( QTextOption::WrapAtWordBoundaryOrAnywhere ); - textOption.setTextDirection ( opt.direction ); - textOption.setAlignment ( QStyle::visualAlignment ( opt.direction, opt.displayAlignment ) ); + textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); + textOption.setTextDirection(opt.direction); + textOption.setAlignment(QStyle::visualAlignment(opt.direction, opt.displayAlignment)); QTextLayout textLayout; - textLayout.setTextOption ( textOption ); - textLayout.setFont ( opt.font ); - textLayout.setText ( opt.text ); + textLayout.setTextOption(textOption); + textLayout.setFont(opt.font); + textLayout.setText(opt.text); qreal width, height; - viewItemTextLayout ( textLayout, textRect.width(), height, width ); + viewItemTextLayout(textLayout, textRect.width(), height, width); const int lineCount = textLayout.lineCount(); - const QRect layoutRect = QStyle::alignedRect ( opt.direction, opt.displayAlignment, QSize ( textRect.width(), int ( height ) ), textRect ); + const QRect layoutRect = QStyle::alignedRect( + opt.direction, opt.displayAlignment, QSize(textRect.width(), int(height)), textRect); const QPointF position = layoutRect.topLeft(); - for ( int i = 0; i < lineCount; ++i ) + for (int i = 0; i < lineCount; ++i) { - const QTextLine line = textLayout.lineAt ( i ); - line.draw ( painter, position ); + const QTextLine line = textLayout.lineAt(i); + line.draw(painter, position); } painter->restore(); } - -QSize ListViewDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const +QSize ListViewDelegate::sizeHint(const QStyleOptionViewItem &option, + const QModelIndex &index) const { QStyleOptionViewItemV4 opt = option; - initStyleOption ( &opt, index ); + initStyleOption(&opt, index); opt.features |= QStyleOptionViewItem::WrapText; opt.text = index.data().toString(); opt.textElideMode = Qt::ElideRight; opt.displayAlignment = Qt::AlignTop | Qt::AlignHCenter; QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); - const int textMargin = style->pixelMetric ( QStyle::PM_FocusFrameHMargin, &option, opt.widget ) + 1; + const int textMargin = + style->pixelMetric(QStyle::PM_FocusFrameHMargin, &option, opt.widget) + 1; int height = 48 + textMargin * 2 + 5; // TODO: turn constants into variables - QSize szz = viewItemTextSize ( &opt ); + QSize szz = viewItemTextSize(&opt); height += szz.height(); // FIXME: maybe the icon items could scale and keep proportions? - QSize sz ( 100,height ); + QSize sz(100, height); return sz; } - -- cgit v1.2.3