From 6bc9df84d9e72d8ee06c23c505b6c5ad54820115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 9 Oct 2013 02:03:02 +0200 Subject: [PATCH] Mod info, with less HTML! And responding to keyboard events too. --- gui/LegacyModEditDialog.cpp | 62 ++++++----- gui/LegacyModEditDialog.h | 6 +- gui/MCModInfoFrame.cpp | 39 +++---- gui/MCModInfoFrame.h | 11 +- gui/MCModInfoFrame.ui | 201 +++++++++++++----------------------- gui/OneSixModEditDialog.cpp | 20 ++-- gui/OneSixModEditDialog.h | 36 ++++--- 7 files changed, 168 insertions(+), 207 deletions(-) diff --git a/gui/LegacyModEditDialog.cpp b/gui/LegacyModEditDialog.cpp index 585bfdfb..82532cfd 100644 --- a/gui/LegacyModEditDialog.cpp +++ b/gui/LegacyModEditDialog.cpp @@ -47,6 +47,9 @@ LegacyModEditDialog::LegacyModEditDialog(LegacyInstance *inst, QWidget *parent) #endif ui->jarModsTreeView->installEventFilter(this); m_jarmods->startWatching(); + auto smodel = ui->jarModsTreeView->selectionModel(); + connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), + SLOT(jarCurrent(QModelIndex, QModelIndex))); } // Core mods { @@ -55,6 +58,9 @@ LegacyModEditDialog::LegacyModEditDialog(LegacyInstance *inst, QWidget *parent) ui->coreModsTreeView->setModel(m_coremods.get()); ui->coreModsTreeView->installEventFilter(this); m_coremods->startWatching(); + auto smodel = ui->coreModsTreeView->selectionModel(); + connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), + SLOT(coreCurrent(QModelIndex, QModelIndex))); } // Loader mods { @@ -63,6 +69,9 @@ LegacyModEditDialog::LegacyModEditDialog(LegacyInstance *inst, QWidget *parent) ui->loaderModTreeView->setModel(m_mods.get()); ui->loaderModTreeView->installEventFilter(this); m_mods->startWatching(); + auto smodel = ui->loaderModTreeView->selectionModel(); + connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), + SLOT(loaderCurrent(QModelIndex, QModelIndex))); } // texture packs { @@ -201,7 +210,7 @@ void LegacyModEditDialog::on_addForgeBtn_clicked() if (vselect.exec() && vselect.selectedVersion()) { ForgeVersionPtr forge = - std::dynamic_pointer_cast (vselect.selectedVersion()); + std::dynamic_pointer_cast(vselect.selectedVersion()); if (!forge) return; auto entry = MMC->metacache()->resolveEntry("minecraftforge", forge->filename); @@ -345,41 +354,38 @@ void LegacyModEditDialog::on_buttonBox_rejected() close(); } -void LegacyModEditDialog::on_jarModsTreeView_pressed(const QModelIndex &index) +void LegacyModEditDialog::jarCurrent(QModelIndex current, QModelIndex previous) { - int first, last; - auto list = ui->jarModsTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) + if(!current.isValid()) + { + ui->jarMIFrame->clear(); return; - - Mod &m = m_jarmods->operator[](first); - - handleModInfoUpdate(m, ui->jarMIFrame); + } + int row = current.row(); + Mod &m = m_jarmods->operator[](row); + ui->jarMIFrame->updateWithMod(m); } -void LegacyModEditDialog::on_coreModsTreeView_pressed(const QModelIndex &index) +void LegacyModEditDialog::coreCurrent(QModelIndex current, QModelIndex previous) { - int first, last; - auto list = ui->coreModsTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) + if(!current.isValid()) + { + ui->coreMIFrame->clear(); return; - - Mod &m = m_coremods->operator[](first); - - handleModInfoUpdate(m, ui->coreMIFrame); + } + int row = current.row(); + Mod &m = m_coremods->operator[](row); + ui->coreMIFrame->updateWithMod(m); } -void LegacyModEditDialog::on_loaderModTreeView_pressed(const QModelIndex &index) +void LegacyModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previous) { - int first, last; - auto list = ui->loaderModTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) + if(!current.isValid()) + { + ui->loaderMIFrame->clear(); return; - - Mod &m = m_mods->operator[](first); - - handleModInfoUpdate(m, ui->loaderMIFrame); + } + int row = current.row(); + Mod &m = m_mods->operator[](row); + ui->loaderMIFrame->updateWithMod(m); } diff --git a/gui/LegacyModEditDialog.h b/gui/LegacyModEditDialog.h index b5d51fd5..fc3ea1e6 100644 --- a/gui/LegacyModEditDialog.h +++ b/gui/LegacyModEditDialog.h @@ -56,9 +56,9 @@ slots: // Questionable: SettingsDialog doesn't need this for some reason? void on_buttonBox_rejected(); - void on_jarModsTreeView_pressed(const QModelIndex &index); - void on_coreModsTreeView_pressed(const QModelIndex &index); - void on_loaderModTreeView_pressed(const QModelIndex &index); + void jarCurrent(QModelIndex current, QModelIndex previous); + void coreCurrent(QModelIndex current, QModelIndex previous); + void loaderCurrent(QModelIndex current, QModelIndex previous); protected: bool eventFilter(QObject *obj, QEvent *ev); diff --git a/gui/MCModInfoFrame.cpp b/gui/MCModInfoFrame.cpp index 70cfd46a..15ead7ab 100644 --- a/gui/MCModInfoFrame.cpp +++ b/gui/MCModInfoFrame.cpp @@ -15,21 +15,15 @@ #include "MCModInfoFrame.h" #include "ui_MCModInfoFrame.h" - -void handleModInfoUpdate(Mod &m, MCModInfoFrame *frame) +void MCModInfoFrame::updateWithMod(Mod &m) { if(m.type() == m.MOD_FOLDER) { - frame->setName("

Select a mod to view information...

"); - frame->setDescription("

Mod description

"); - frame->setAuthors("

Mod authors

"); - frame->setCredits("

Mod credits

"); - frame->setWebsite("

Mod website

"); - + clear(); return; } - QString missing = "

Missing from mcmod.info

"; + QString missing = tr("Missing from mcmod.info"); QString name = m.name(); if(name.isEmpty()) name = missing; @@ -43,11 +37,20 @@ void handleModInfoUpdate(Mod &m, MCModInfoFrame *frame) if(website.isEmpty()) website = missing; else website = "" + website + ""; - frame->setName("

" + name + "

"); - frame->setDescription(description); - frame->setAuthors(authors); - frame->setCredits(credits); - frame->setWebsite(website); + setName(name); + setDescription(description); + setAuthors(authors); + setCredits(credits); + setWebsite(website); +} + +void MCModInfoFrame::clear() +{ + setName(tr("Select a mod to view information...")); + setDescription(tr("Mod description")); + setAuthors(tr("Mod authors")); + setCredits(tr("Mod credits")); + setWebsite(tr("Mod website")); } MCModInfoFrame::MCModInfoFrame(QWidget *parent) : @@ -65,25 +68,25 @@ MCModInfoFrame::~MCModInfoFrame() void MCModInfoFrame::setName(QString name) { ui->label_Name->setText(name); - ui->label_Name->setToolTip(name); + //ui->label_Name->setToolTip(name); } void MCModInfoFrame::setDescription(QString description) { ui->label_Description->setText(description); - ui->label_Description->setToolTip(description); + //ui->label_Description->setToolTip(description); } void MCModInfoFrame::setAuthors(QString authors) { ui->label_Authors->setText(authors); - ui->label_Authors->setToolTip(authors); + //ui->label_Authors->setToolTip(authors); } void MCModInfoFrame::setCredits(QString credits) { ui->label_Credits->setText(credits); - ui->label_Credits->setToolTip(credits); + //ui->label_Credits->setToolTip(credits); } void MCModInfoFrame::setWebsite(QString website) diff --git a/gui/MCModInfoFrame.h b/gui/MCModInfoFrame.h index 516fc5ed..01812df7 100644 --- a/gui/MCModInfoFrame.h +++ b/gui/MCModInfoFrame.h @@ -18,14 +18,15 @@ #include #include "logic/Mod.h" -namespace Ui { +namespace Ui +{ class MCModInfoFrame; } class MCModInfoFrame : public QFrame { Q_OBJECT - + public: explicit MCModInfoFrame(QWidget *parent = 0); ~MCModInfoFrame(); @@ -36,9 +37,9 @@ public: void setCredits(QString credits); void setWebsite(QString website); - + void updateWithMod(Mod &m); + void clear(); + private: Ui::MCModInfoFrame *ui; }; - -void handleModInfoUpdate(Mod &m, MCModInfoFrame *frame); diff --git a/gui/MCModInfoFrame.ui b/gui/MCModInfoFrame.ui index 73b93a2e..41902c1a 100644 --- a/gui/MCModInfoFrame.ui +++ b/gui/MCModInfoFrame.ui @@ -2,136 +2,81 @@ MCModInfoFrame - - - 0 - 0 - 571 - 55 - - Frame - - QFrame::StyledPanel - - - QFrame::Raised - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - 0 - - - - - 250 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 9 - - - 0 - - - - - - 0 - 0 - - - - - 250 - 0 - - - - - 16777215 - 92 - - - - <html><head/><body><p><span style=" font-size:9pt; font-weight:600; font-style:italic;">Select a mod to view information...</span></p></body></html> - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - - - - - - 0 - 0 - - - - - 250 - 0 - - - - - 16777215 - 92 - - - - <html><head/><body><p><span style=" font-style:italic;">Mod description</span></p></body></html> - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - - - + + + + + + 0 + 0 + + + + + 250 + 0 + + + + + 16777215 + 92 + + + + + 75 + true + + + + Select a mod to view information... + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + + 0 + 0 + + + + + 250 + 0 + + + + + 16777215 + 92 + + + + Mod description + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + @@ -169,7 +114,7 @@ - <html><head/><body><p><span style=" font-style:italic; color:#4a4a4a;">Mod authors</span></p></body></html> + Mod authors Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop @@ -204,7 +149,7 @@ - <html><head/><body><p><span style=" font-style:italic; color:#4a4a4a;">Mod website</span></p></body></html> + Mod website Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop @@ -232,7 +177,7 @@ - <html><head/><body><p><span style=" font-style:italic; color:#4a4a4a;">Mod credits</span></p></body></html> + Mod credits Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop diff --git a/gui/OneSixModEditDialog.cpp b/gui/OneSixModEditDialog.cpp index 9724cec5..e072a238 100644 --- a/gui/OneSixModEditDialog.cpp +++ b/gui/OneSixModEditDialog.cpp @@ -60,6 +60,9 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent) ui->loaderModTreeView->setModel(m_mods.get()); ui->loaderModTreeView->installEventFilter(this); m_mods->startWatching(); + auto smodel = ui->loaderModTreeView->selectionModel(); + connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), + SLOT(loaderCurrent(QModelIndex,QModelIndex))); } // resource packs { @@ -298,15 +301,14 @@ void OneSixModEditDialog::on_viewResPackBtn_clicked() openDirInDefaultProgram(m_inst->resourcePacksDir(), true); } -void OneSixModEditDialog::on_loaderModTreeView_pressed(const QModelIndex &index) +void OneSixModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previous) { - int first, last; - auto list = ui->loaderModTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) + if(!current.isValid()) + { + ui->frame->clear(); return; - - Mod &m = m_mods->operator[](first); - - handleModInfoUpdate(m, ui->frame); + } + int row = current.row(); + Mod &m = m_mods->operator[](row); + ui->frame->updateWithMod(m); } diff --git a/gui/OneSixModEditDialog.h b/gui/OneSixModEditDialog.h index 03ebf7a3..5376e526 100644 --- a/gui/OneSixModEditDialog.h +++ b/gui/OneSixModEditDialog.h @@ -1,9 +1,9 @@ /* Copyright 2013 MultiMC Contributors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software @@ -19,23 +19,25 @@ #include class EnabledItemFilter; -namespace Ui { - class OneSixModEditDialog; +namespace Ui +{ +class OneSixModEditDialog; } class OneSixModEditDialog : public QDialog { Q_OBJECT - + public: - explicit OneSixModEditDialog(OneSixInstance* inst, QWidget *parent = 0); + explicit OneSixModEditDialog(OneSixInstance *inst, QWidget *parent = 0); virtual ~OneSixModEditDialog(); - -private slots: + +private +slots: void on_addModBtn_clicked(); void on_rmModBtn_clicked(); void on_viewModBtn_clicked(); - + void on_addResPackBtn_clicked(); void on_rmResPackBtn_clicked(); void on_viewResPackBtn_clicked(); @@ -44,20 +46,22 @@ private slots: void on_forgeBtn_clicked(); void on_customizeBtn_clicked(); void on_revertBtn_clicked(); - void updateVersionControls(); + void updateVersionControls(); void disableVersionControls(); - void on_loaderModTreeView_pressed(const QModelIndex &index); - protected: bool eventFilter(QObject *obj, QEvent *ev); - bool loaderListFilter( QKeyEvent* ev ); - bool resourcePackListFilter( QKeyEvent* ev ); + bool loaderListFilter(QKeyEvent *ev); + bool resourcePackListFilter(QKeyEvent *ev); + private: Ui::OneSixModEditDialog *ui; std::shared_ptr m_version; std::shared_ptr m_mods; std::shared_ptr m_resourcepacks; - EnabledItemFilter * main_model; - OneSixInstance * m_inst; + EnabledItemFilter *main_model; + OneSixInstance *m_inst; +public +slots: + void loaderCurrent(QModelIndex current, QModelIndex previous); };