summaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
authorAndrew <forkk@forkk.net>2013-12-01 14:28:47 -0600
committerAndrew <forkk@forkk.net>2013-12-01 14:28:47 -0600
commit613699b3626aea750093ab7eaaeccaa28c0e87c6 (patch)
tree7fd542b8f4be10359ba2aaeac9834f1b5c86a750 /gui
parent2427ad687137bbcfc7303a931d7e0b74d5325e48 (diff)
parent75c4d97b90e39f2bda6e682def0fdda044cbcf6f (diff)
downloadMultiMC-613699b3626aea750093ab7eaaeccaa28c0e87c6.tar
MultiMC-613699b3626aea750093ab7eaaeccaa28c0e87c6.tar.gz
MultiMC-613699b3626aea750093ab7eaaeccaa28c0e87c6.tar.lz
MultiMC-613699b3626aea750093ab7eaaeccaa28c0e87c6.tar.xz
MultiMC-613699b3626aea750093ab7eaaeccaa28c0e87c6.zip
Merge branch 'develop' of github.com:MultiMC/MultiMC5 into develop
Diffstat (limited to 'gui')
-rw-r--r--gui/ConsoleWindow.cpp21
-rw-r--r--gui/ConsoleWindow.h21
-rw-r--r--gui/MainWindow.cpp58
-rw-r--r--gui/dialogs/AccountListDialog.cpp17
-rw-r--r--gui/dialogs/AccountListDialog.h6
-rw-r--r--gui/dialogs/AccountSelectDialog.cpp8
-rw-r--r--gui/dialogs/AccountSelectDialog.h10
-rw-r--r--gui/dialogs/CopyInstanceDialog.cpp2
-rw-r--r--gui/dialogs/EditAccountDialog.cpp10
-rw-r--r--gui/dialogs/EditAccountDialog.h11
-rw-r--r--gui/dialogs/EditNotesDialog.cpp4
-rw-r--r--gui/dialogs/InstanceSettings.cpp2
-rw-r--r--gui/dialogs/LegacyModEditDialog.cpp2
-rw-r--r--gui/dialogs/OneSixModEditDialog.cpp2
-rw-r--r--gui/widgets/InstanceDelegate.cpp176
15 files changed, 198 insertions, 152 deletions
diff --git a/gui/ConsoleWindow.cpp b/gui/ConsoleWindow.cpp
index d8a1b69d..d0210df6 100644
--- a/gui/ConsoleWindow.cpp
+++ b/gui/ConsoleWindow.cpp
@@ -58,13 +58,23 @@ void ConsoleWindow::writeColor(QString text, const char *color)
ui->text->appendHtml(QString("<font color=\"%1\">%2</font>").arg(color).arg(text));
else
ui->text->appendPlainText(text);
- // scroll down
- QScrollBar *bar = ui->text->verticalScrollBar();
- bar->setValue(bar->maximum());
}
void ConsoleWindow::write(QString data, MessageLevel::Enum mode)
{
+ QScrollBar *bar = ui->text->verticalScrollBar();
+ int max_bar = bar->maximum();
+ int val_bar = bar->value();
+ if(m_scroll_active)
+ {
+ if(m_last_scroll_value > val_bar)
+ m_scroll_active = false;
+ }
+ else
+ {
+ m_scroll_active = val_bar == max_bar;
+ }
+
if (data.endsWith('\n'))
data = data.left(data.length() - 1);
QStringList paragraphs = data.split('\n');
@@ -93,6 +103,11 @@ void ConsoleWindow::write(QString data, MessageLevel::Enum mode)
else
while (iter.hasNext())
writeColor(iter.next());
+ if(m_scroll_active)
+ {
+ bar->setValue(bar->maximum());
+ }
+ m_last_scroll_value = bar->value();
}
void ConsoleWindow::clear()
diff --git a/gui/ConsoleWindow.h b/gui/ConsoleWindow.h
index e0a47bc6..2d948484 100644
--- a/gui/ConsoleWindow.h
+++ b/gui/ConsoleWindow.h
@@ -38,6 +38,16 @@ public:
*/
void setMayClose(bool mayclose);
+private:
+ /**
+ * @brief write a colored paragraph
+ * @param data the string
+ * @param color the css color name
+ * this will only insert a single paragraph.
+ * \n are ignored. a real \n is always appended.
+ */
+ void writeColor(QString data, const char *color = nullptr);
+
signals:
void isClosing();
@@ -52,15 +62,6 @@ slots:
void write(QString data, MessageLevel::Enum level = MessageLevel::MultiMC);
/**
- * @brief write a colored paragraph
- * @param data the string
- * @param color the css color name
- * this will only insert a single paragraph.
- * \n are ignored. a real \n is always appended.
- */
- void writeColor(QString data, const char *color = nullptr);
-
- /**
* @brief clear the text widget
*/
void clear();
@@ -82,4 +83,6 @@ private:
Ui::ConsoleWindow *ui = nullptr;
MinecraftProcess *proc = nullptr;
bool m_mayclose = true;
+ int m_last_scroll_value = 0;
+ bool m_scroll_active = true;
};
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp
index cb81958b..854091c6 100644
--- a/gui/MainWindow.cpp
+++ b/gui/MainWindow.cpp
@@ -69,8 +69,9 @@
#include "logic/lists/IconList.h"
#include "logic/lists/JavaVersionList.h"
-#include "logic/auth/AuthenticateTask.h"
-#include "logic/auth/ValidateTask.h"
+#include "logic/auth/flows/AuthenticateTask.h"
+#include "logic/auth/flows/RefreshTask.h"
+#include "logic/auth/flows/ValidateTask.h"
#include "logic/BaseInstance.h"
#include "logic/InstanceFactory.h"
@@ -244,6 +245,28 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
connect(assets_downloader, SIGNAL(finished()), SLOT(assetsFinished()));
assets_downloader->start();
}
+
+ const QString currentInstanceId = MMC->settings()->get("SelectedInstance").toString();
+ if (!currentInstanceId.isNull())
+ {
+ const QModelIndex index = MMC->instances()->getInstanceIndexById(currentInstanceId);
+ if (index.isValid())
+ {
+ const QModelIndex mappedIndex = proxymodel->mapFromSource(index);
+ view->setCurrentIndex(mappedIndex);
+ }
+ else
+ {
+ view->setCurrentIndex(proxymodel->index(0, 0));
+ }
+ }
+ else
+ {
+ view->setCurrentIndex(proxymodel->index(0, 0));
+ }
+
+ // removing this looks stupid
+ view->setFocus();
}
MainWindow::~MainWindow()
@@ -254,7 +277,6 @@ MainWindow::~MainWindow()
delete assets_downloader;
}
-
void MainWindow::repopulateAccountsMenu()
{
accountMenu->clear();
@@ -769,16 +791,16 @@ void MainWindow::doLaunchInst(BaseInstance* instance, MojangAccountPtr account)
{
// We'll need to validate the access token to make sure the account is still logged in.
ProgressDialog progDialog(this);
- ValidateTask validateTask(account, &progDialog);
- progDialog.exec(&validateTask);
-
- if (validateTask.successful())
+ RefreshTask refreshtask(account, &progDialog);
+ progDialog.exec(&refreshtask);
+
+ if (refreshtask.successful())
{
prepareLaunch(m_selectedInstance, account);
}
else
{
- YggdrasilTask::Error* error = validateTask.getError();
+ YggdrasilTask::Error *error = refreshtask.getError();
if (error != nullptr)
{
@@ -790,17 +812,20 @@ void MainWindow::doLaunchInst(BaseInstance* instance, MojangAccountPtr account)
}
else
{
- CustomMessageBox::selectable(this, tr("Access Token Validation Error"),
+ CustomMessageBox::selectable(
+ this, tr("Access Token Validation Error"),
tr("There was an error when trying to validate your access token.\n"
- "Details: %s").arg(error->getDisplayMessage()),
+ "Details: %s").arg(error->getDisplayMessage()),
QMessageBox::Warning, QMessageBox::Ok)->exec();
}
}
else
{
- CustomMessageBox::selectable(this, tr("Access Token Validation Error"),
+ CustomMessageBox::selectable(
+ this, tr("Access Token Validation Error"),
tr("There was an unknown error when trying to validate your access token."
- "The authentication server might be down, or you might not be connected to the Internet."),
+ "The authentication server might be down, or you might not be connected to "
+ "the Internet."),
QMessageBox::Warning, QMessageBox::Ok)->exec();
}
}
@@ -857,10 +882,7 @@ void MainWindow::launchInstance(BaseInstance *instance, MojangAccountPtr account
console = new ConsoleWindow(proc);
connect(console, SIGNAL(isClosing()), this, SLOT(instanceEnded()));
- // I think this will work...
- QString username = account->username();
- QString session_id = account->accessToken();
- proc->setLogin(username, session_id);
+ proc->setLogin(account);
proc->launch();
}
@@ -983,10 +1005,14 @@ void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &
m_statusLeft->setText(m_selectedInstance->getStatusbarDescription());
auto ico = MMC->icons()->getIcon(iconKey);
ui->actionChangeInstIcon->setIcon(ico);
+
+ MMC->settings()->set("SelectedInstance", m_selectedInstance->id());
}
else
{
selectionBad();
+
+ MMC->settings()->set("SelectedInstance", QString());
}
}
diff --git a/gui/dialogs/AccountListDialog.cpp b/gui/dialogs/AccountListDialog.cpp
index dfac4989..f5268b61 100644
--- a/gui/dialogs/AccountListDialog.cpp
+++ b/gui/dialogs/AccountListDialog.cpp
@@ -20,7 +20,7 @@
#include <logger/QsLog.h>
-#include <logic/auth/AuthenticateTask.h>
+#include <logic/auth/flows/AuthenticateTask.h>
#include <logic/net/NetJob.h>
#include <gui/dialogs/EditAccountDialog.h>
@@ -29,9 +29,8 @@
#include <MultiMC.h>
-AccountListDialog::AccountListDialog(QWidget *parent) :
- QDialog(parent),
- ui(new Ui::AccountListDialog)
+AccountListDialog::AccountListDialog(QWidget *parent)
+ : QDialog(parent), ui(new Ui::AccountListDialog)
{
ui->setupUi(this);
@@ -44,8 +43,8 @@ AccountListDialog::AccountListDialog(QWidget *parent) :
connect(selectionModel, &QItemSelectionModel::selectionChanged,
[this] (const QItemSelection& sel, const QItemSelection& dsel) { updateButtonStates(); });
- connect(m_accounts.get(), SIGNAL(listChanged), SLOT(listChanged));
- connect(m_accounts.get(), SIGNAL(activeAccountChanged), SLOT(listChanged));
+ connect(m_accounts.get(), SIGNAL(listChanged()), SLOT(listChanged()));
+ connect(m_accounts.get(), SIGNAL(activeAccountChanged()), SLOT(listChanged()));
updateButtonStates();
}
@@ -60,7 +59,6 @@ void AccountListDialog::listChanged()
updateButtonStates();
}
-
void AccountListDialog::on_addAccountBtn_clicked()
{
addAccount(tr("Please enter your Mojang or Minecraft account username and password to add your account."));
@@ -84,7 +82,7 @@ void AccountListDialog::on_setDefaultBtn_clicked()
QModelIndex selected = selection.first();
MojangAccountPtr account = selected.data(MojangAccountList::PointerRole).value<MojangAccountPtr>();
m_accounts->setActiveAccount(account->username());
- }
+ }
}
void AccountListDialog::on_noDefaultBtn_clicked()
@@ -104,7 +102,7 @@ void AccountListDialog::updateButtonStates()
ui->rmAccountBtn->setEnabled(selection.size() > 0);
ui->setDefaultBtn->setEnabled(selection.size() > 0);
-
+
ui->noDefaultBtn->setDown(m_accounts->activeAccount().get() == nullptr);
}
@@ -146,4 +144,3 @@ void AccountListDialog::addAccount(const QString& errMsg)
}
}
}
-
diff --git a/gui/dialogs/AccountListDialog.h b/gui/dialogs/AccountListDialog.h
index 634d944a..84ff8e0e 100644
--- a/gui/dialogs/AccountListDialog.h
+++ b/gui/dialogs/AccountListDialog.h
@@ -21,7 +21,8 @@
#include "logic/lists/MojangAccountList.h"
-namespace Ui {
+namespace Ui
+{
class AccountListDialog;
}
@@ -29,7 +30,7 @@ class AuthenticateTask;
class AccountListDialog : public QDialog
{
-Q_OBJECT
+ Q_OBJECT
public:
explicit AccountListDialog(QWidget *parent = 0);
~AccountListDialog();
@@ -62,4 +63,3 @@ slots:
private:
Ui::AccountListDialog *ui;
};
-
diff --git a/gui/dialogs/AccountSelectDialog.cpp b/gui/dialogs/AccountSelectDialog.cpp
index db1bd192..b8fa9e42 100644
--- a/gui/dialogs/AccountSelectDialog.cpp
+++ b/gui/dialogs/AccountSelectDialog.cpp
@@ -20,15 +20,14 @@
#include <logger/QsLog.h>
-#include <logic/auth/AuthenticateTask.h>
+#include <logic/auth/flows/AuthenticateTask.h>
#include <gui/dialogs/ProgressDialog.h>
#include <MultiMC.h>
-AccountSelectDialog::AccountSelectDialog(const QString& message, int flags, QWidget *parent) :
- QDialog(parent),
- ui(new Ui::AccountSelectDialog)
+AccountSelectDialog::AccountSelectDialog(const QString &message, int flags, QWidget *parent)
+ : QDialog(parent), ui(new Ui::AccountSelectDialog)
{
ui->setupUi(this);
@@ -85,4 +84,3 @@ void AccountSelectDialog::on_buttonBox_rejected()
{
close();
}
-
diff --git a/gui/dialogs/AccountSelectDialog.h b/gui/dialogs/AccountSelectDialog.h
index 41af4f7c..a539e7e9 100644
--- a/gui/dialogs/AccountSelectDialog.h
+++ b/gui/dialogs/AccountSelectDialog.h
@@ -21,17 +21,18 @@
#include "logic/lists/MojangAccountList.h"
-namespace Ui {
+namespace Ui
+{
class AccountSelectDialog;
}
class AccountSelectDialog : public QDialog
{
-Q_OBJECT
+ Q_OBJECT
public:
enum Flags
{
- NoFlags=0,
+ NoFlags = 0,
/*!
* Shows a check box on the dialog that allows the user to specify that the account
@@ -75,7 +76,7 @@ public:
public
slots:
void on_buttonBox_accepted();
-
+
void on_buttonBox_rejected();
protected:
@@ -87,4 +88,3 @@ protected:
private:
Ui::AccountSelectDialog *ui;
};
-
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/EditAccountDialog.cpp b/gui/dialogs/EditAccountDialog.cpp
index d28336f7..dd3f0523 100644
--- a/gui/dialogs/EditAccountDialog.cpp
+++ b/gui/dialogs/EditAccountDialog.cpp
@@ -16,11 +16,10 @@
#include "EditAccountDialog.h"
#include "ui_EditAccountDialog.h"
-EditAccountDialog::EditAccountDialog(const QString& text, QWidget *parent, int flags) :
- QDialog(parent),
- ui(new Ui::EditAccountDialog)
+EditAccountDialog::EditAccountDialog(const QString &text, QWidget *parent, int flags)
+ : QDialog(parent), ui(new Ui::EditAccountDialog)
{
- ui->setupUi(this);
+ ui->setupUi(this);
ui->label->setText(text);
ui->label->setVisible(!text.isEmpty());
@@ -31,7 +30,7 @@ EditAccountDialog::EditAccountDialog(const QString& text, QWidget *parent, int f
EditAccountDialog::~EditAccountDialog()
{
- delete ui;
+ delete ui;
}
QString EditAccountDialog::username() const
@@ -43,4 +42,3 @@ QString EditAccountDialog::password() const
{
return ui->passTextBox->text();
}
-
diff --git a/gui/dialogs/EditAccountDialog.h b/gui/dialogs/EditAccountDialog.h
index 847c3be5..be3a88d8 100644
--- a/gui/dialogs/EditAccountDialog.h
+++ b/gui/dialogs/EditAccountDialog.h
@@ -17,16 +17,18 @@
#include <QDialog>
-namespace Ui {
+namespace Ui
+{
class EditAccountDialog;
}
class EditAccountDialog : public QDialog
{
-Q_OBJECT
+ Q_OBJECT
public:
- explicit EditAccountDialog(const QString& text="", QWidget *parent = 0, int flags=UsernameField | PasswordField);
+ explicit EditAccountDialog(const QString &text = "", QWidget *parent = 0,
+ int flags = UsernameField | PasswordField);
~EditAccountDialog();
/*!
@@ -41,7 +43,7 @@ public:
enum Flags
{
- NoFlags=0,
+ NoFlags = 0,
//! Specifies that the dialog should have a username field.
UsernameField,
@@ -53,4 +55,3 @@ public:
private:
Ui::EditAccountDialog *ui;
};
-
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 <QApplication>
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 <QMessageBox>
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 <QKeyEvent>
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 <QtCore/qmath.h>
// 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;
}
-