Merge remote-tracking branch 'upstream/develop' into rework-settings
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
commit
618e6bd96b
295 changed files with 11681 additions and 2609 deletions
|
@ -178,7 +178,7 @@ QStringList CheckComboBox::checkedItems() const
|
|||
|
||||
void CheckComboBox::setCheckedItems(const QStringList& items)
|
||||
{
|
||||
foreach (auto text, items) {
|
||||
for (auto text : items) {
|
||||
auto index = findText(text);
|
||||
setItemCheckState(index, index != -1 ? Qt::Checked : Qt::Unchecked);
|
||||
}
|
||||
|
|
|
@ -287,7 +287,7 @@ void InfoFrame::setDescription(QString text)
|
|||
QChar rem('\n');
|
||||
QString finaltext;
|
||||
finaltext.reserve(intermediatetext.size());
|
||||
foreach (const QChar& c, intermediatetext) {
|
||||
for (const QChar& c : intermediatetext) {
|
||||
if (c == rem && prev) {
|
||||
continue;
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ void InfoFrame::setLicense(QString text)
|
|||
QChar rem('\n');
|
||||
QString finaltext;
|
||||
finaltext.reserve(intermediatetext.size());
|
||||
foreach (const QChar& c, intermediatetext) {
|
||||
for (const QChar& c : intermediatetext) {
|
||||
if (c == rem && prev) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ LogView::LogView(QWidget* parent) : QPlainTextEdit(parent)
|
|||
{
|
||||
setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
|
||||
m_defaultFormat = new QTextCharFormat(currentCharFormat());
|
||||
setUndoRedoEnabled(false);
|
||||
}
|
||||
|
||||
LogView::~LogView()
|
||||
|
@ -60,6 +61,14 @@ void LogView::setWordWrap(bool wrapping)
|
|||
}
|
||||
}
|
||||
|
||||
void LogView::setColorLines(bool colorLines)
|
||||
{
|
||||
if (m_colorLines == colorLines)
|
||||
return;
|
||||
m_colorLines = colorLines;
|
||||
repopulate();
|
||||
}
|
||||
|
||||
void LogView::setModel(QAbstractItemModel* model)
|
||||
{
|
||||
if (m_model) {
|
||||
|
@ -121,6 +130,8 @@ void LogView::rowsInserted(const QModelIndex& parent, int first, int last)
|
|||
QTextDocument document;
|
||||
QTextCursor cursor(&document);
|
||||
|
||||
cursor.movePosition(QTextCursor::End);
|
||||
cursor.beginEditBlock();
|
||||
for (int i = first; i <= last; i++) {
|
||||
auto idx = m_model->index(i, 0, parent);
|
||||
auto text = m_model->data(idx, Qt::DisplayRole).toString();
|
||||
|
@ -130,17 +141,17 @@ void LogView::rowsInserted(const QModelIndex& parent, int first, int last)
|
|||
format.setFont(font.value<QFont>());
|
||||
}
|
||||
auto fg = m_model->data(idx, Qt::ForegroundRole);
|
||||
if (fg.isValid()) {
|
||||
if (fg.isValid() && m_colorLines) {
|
||||
format.setForeground(fg.value<QColor>());
|
||||
}
|
||||
auto bg = m_model->data(idx, Qt::BackgroundRole);
|
||||
if (bg.isValid()) {
|
||||
if (bg.isValid() && m_colorLines) {
|
||||
format.setBackground(bg.value<QColor>());
|
||||
}
|
||||
cursor.movePosition(QTextCursor::End);
|
||||
cursor.insertText(text, format);
|
||||
cursor.insertBlock();
|
||||
}
|
||||
cursor.endEditBlock();
|
||||
|
||||
QTextDocumentFragment fragment(&document);
|
||||
QTextCursor workCursor = textCursor();
|
||||
|
|
|
@ -15,6 +15,7 @@ class LogView : public QPlainTextEdit {
|
|||
|
||||
public slots:
|
||||
void setWordWrap(bool wrapping);
|
||||
void setColorLines(bool colorLines);
|
||||
void findNext(const QString& what, bool reverse);
|
||||
void scrollToBottom();
|
||||
|
||||
|
@ -32,4 +33,5 @@ class LogView : public QPlainTextEdit {
|
|||
QTextCharFormat* m_defaultFormat = nullptr;
|
||||
bool m_scroll = false;
|
||||
bool m_scrolling = false;
|
||||
bool m_colorLines = true;
|
||||
};
|
||||
|
|
|
@ -49,9 +49,9 @@
|
|||
#include "Application.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
|
||||
unique_qobject_ptr<ModFilterWidget> ModFilterWidget::create(MinecraftInstance* instance, bool extended, QWidget* parent)
|
||||
std::unique_ptr<ModFilterWidget> ModFilterWidget::create(MinecraftInstance* instance, bool extended)
|
||||
{
|
||||
return unique_qobject_ptr<ModFilterWidget>(new ModFilterWidget(instance, extended, parent));
|
||||
return std::unique_ptr<ModFilterWidget>(new ModFilterWidget(instance, extended));
|
||||
}
|
||||
|
||||
class VersionBasicModel : public QIdentityProxyModel {
|
||||
|
@ -107,8 +107,8 @@ class AllVersionProxyModel : public QSortFilterProxyModel {
|
|||
}
|
||||
};
|
||||
|
||||
ModFilterWidget::ModFilterWidget(MinecraftInstance* instance, bool extended, QWidget* parent)
|
||||
: QTabWidget(parent), ui(new Ui::ModFilterWidget), m_instance(instance), m_filter(new Filter())
|
||||
ModFilterWidget::ModFilterWidget(MinecraftInstance* instance, bool extended)
|
||||
: QTabWidget(), ui(new Ui::ModFilterWidget), m_instance(instance), m_filter(new Filter())
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
|
@ -291,7 +291,6 @@ void ModFilterWidget::onSideFilterChanged()
|
|||
side = "";
|
||||
}
|
||||
|
||||
|
||||
m_filter_changed = side != m_filter->side;
|
||||
m_filter->side = side;
|
||||
if (m_filter_changed)
|
||||
|
|
|
@ -83,7 +83,7 @@ class ModFilterWidget : public QTabWidget {
|
|||
}
|
||||
};
|
||||
|
||||
static unique_qobject_ptr<ModFilterWidget> create(MinecraftInstance* instance, bool extended, QWidget* parent = nullptr);
|
||||
static std::unique_ptr<ModFilterWidget> create(MinecraftInstance* instance, bool extended);
|
||||
virtual ~ModFilterWidget();
|
||||
|
||||
auto getFilter() -> std::shared_ptr<Filter>;
|
||||
|
@ -96,7 +96,7 @@ class ModFilterWidget : public QTabWidget {
|
|||
void setCategories(const QList<ModPlatform::Category>&);
|
||||
|
||||
private:
|
||||
ModFilterWidget(MinecraftInstance* instance, bool extendedSupport, QWidget* parent = nullptr);
|
||||
ModFilterWidget(MinecraftInstance* instance, bool extendedSupport);
|
||||
|
||||
void loadVersionList();
|
||||
void prepareBasicFilter();
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#include "ProjectItem.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include <QApplication>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QIcon>
|
||||
#include <QPainter>
|
||||
#include "Common.h"
|
||||
|
||||
ProjectItemDelegate::ProjectItemDelegate(QWidget* parent) : QStyledItemDelegate(parent) {}
|
||||
|
||||
|
@ -14,13 +16,20 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
|
|||
QStyleOptionViewItem opt(option);
|
||||
initStyleOption(&opt, index);
|
||||
|
||||
const QStyle* style = opt.widget == nullptr ? QApplication::style() : opt.widget->style();
|
||||
|
||||
auto rect = opt.rect;
|
||||
|
||||
if (opt.state & QStyle::State_Selected) {
|
||||
painter->fillRect(rect, opt.palette.highlight());
|
||||
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
|
||||
|
||||
if (option.state & QStyle::State_Selected && style->objectName() != "windowsvista")
|
||||
painter->setPen(opt.palette.highlightedText().color());
|
||||
} else if (opt.state & QStyle::State_MouseOver) {
|
||||
painter->fillRect(rect, opt.palette.window());
|
||||
|
||||
if (opt.features & QStyleOptionViewItem::HasCheckIndicator) {
|
||||
QStyleOptionViewItem checkboxOpt = makeCheckboxStyleOption(opt, style);
|
||||
style->drawPrimitive(QStyle::PE_IndicatorItemViewItemCheck, &checkboxOpt, painter, opt.widget);
|
||||
|
||||
rect.setX(checkboxOpt.rect.right());
|
||||
}
|
||||
|
||||
// The default icon size will be a square (and height is usually the lower value).
|
||||
|
@ -42,6 +51,9 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
|
|||
int x = rect.x() + icon_x_margin;
|
||||
int y = rect.y() + icon_y_margin;
|
||||
|
||||
if (opt.features & QStyleOptionViewItem::HasCheckIndicator)
|
||||
rect.translate(icon_x_margin / 2, 0);
|
||||
|
||||
// Prevent 'scaling null pixmap' warnings
|
||||
if (icon_width > 0 && icon_height > 0)
|
||||
opt.icon.paint(painter, x, y, icon_width, icon_height);
|
||||
|
@ -56,26 +68,12 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
|
|||
{ // Title painting
|
||||
auto title = index.data(UserDataTypes::TITLE).toString();
|
||||
|
||||
if (index.data(UserDataTypes::INSTALLED).toBool())
|
||||
title = tr("%1 [installed]").arg(title);
|
||||
|
||||
painter->save();
|
||||
|
||||
auto font = opt.font;
|
||||
if (index.data(UserDataTypes::SELECTED).toBool()) {
|
||||
// Set nice font
|
||||
font.setBold(true);
|
||||
font.setUnderline(true);
|
||||
}
|
||||
if (index.data(UserDataTypes::INSTALLED).toBool()) {
|
||||
auto hRect = opt.rect;
|
||||
hRect.setX(hRect.x() + 1);
|
||||
hRect.setY(hRect.y() + 1);
|
||||
hRect.setHeight(hRect.height() - 2);
|
||||
hRect.setWidth(hRect.width() - 2);
|
||||
// Set nice font
|
||||
font.setItalic(true);
|
||||
font.setOverline(true);
|
||||
painter->drawRect(hRect);
|
||||
}
|
||||
|
||||
font.setPointSize(font.pointSize() + 2);
|
||||
painter->setFont(font);
|
||||
|
||||
|
@ -132,3 +130,56 @@ void ProjectItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
|
|||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
bool ProjectItemDelegate::editorEvent(QEvent* event,
|
||||
QAbstractItemModel* model,
|
||||
const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index)
|
||||
{
|
||||
if (!(event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::MouseButtonPress ||
|
||||
event->type() == QEvent::MouseButtonDblClick))
|
||||
return false;
|
||||
|
||||
auto mouseEvent = (QMouseEvent*)event;
|
||||
|
||||
if (mouseEvent->button() != Qt::LeftButton)
|
||||
return false;
|
||||
|
||||
QStyleOptionViewItem opt(option);
|
||||
initStyleOption(&opt, index);
|
||||
|
||||
const QStyle* style = opt.widget == nullptr ? QApplication::style() : opt.widget->style();
|
||||
|
||||
const QStyleOptionViewItem checkboxOpt = makeCheckboxStyleOption(opt, style);
|
||||
|
||||
if (!checkboxOpt.rect.contains(mouseEvent->pos().x(), mouseEvent->pos().y()))
|
||||
return false;
|
||||
|
||||
// swallow other events
|
||||
// (prevents item being selected or double click action triggering)
|
||||
if (event->type() != QEvent::MouseButtonRelease)
|
||||
return true;
|
||||
|
||||
emit checkboxClicked(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
QStyleOptionViewItem ProjectItemDelegate::makeCheckboxStyleOption(const QStyleOptionViewItem& opt, const QStyle* style) const
|
||||
{
|
||||
QStyleOptionViewItem checkboxOpt = opt;
|
||||
|
||||
checkboxOpt.state &= ~QStyle::State_HasFocus;
|
||||
|
||||
if (checkboxOpt.checkState == Qt::Checked)
|
||||
checkboxOpt.state |= QStyle::State_On;
|
||||
else
|
||||
checkboxOpt.state |= QStyle::State_Off;
|
||||
|
||||
QRect checkboxRect = style->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &checkboxOpt, opt.widget);
|
||||
// 5px is the typical top margin for image
|
||||
// we don't want the checkboxes to be all over the place :)
|
||||
checkboxOpt.rect = QRect(opt.rect.x() + 5, opt.rect.y() + (opt.rect.height() / 2 - checkboxRect.height() / 2), checkboxRect.width(),
|
||||
checkboxRect.height());
|
||||
|
||||
return checkboxOpt;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
enum UserDataTypes {
|
||||
TITLE = 257, // QString
|
||||
DESCRIPTION = 258, // QString
|
||||
SELECTED = 259, // bool
|
||||
INSTALLED = 260 // bool
|
||||
INSTALLED = 259 // bool
|
||||
};
|
||||
|
||||
/** This is an item delegate composed of:
|
||||
|
@ -22,4 +21,12 @@ class ProjectItemDelegate final : public QStyledItemDelegate {
|
|||
ProjectItemDelegate(QWidget* parent);
|
||||
|
||||
void paint(QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const override;
|
||||
|
||||
bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) override;
|
||||
|
||||
signals:
|
||||
void checkboxClicked(const QModelIndex& index);
|
||||
|
||||
private:
|
||||
QStyleOptionViewItem makeCheckboxStyleOption(const QStyleOptionViewItem& opt, const QStyle* style) const;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue