From ddb961fad5532a33bbd3771fbac840a1d9450d06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 6 Jan 2014 00:33:16 +0100 Subject: Scroll console window for <= lines above the bottom instead of the very bottom. --- gui/ConsoleWindow.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'gui/ConsoleWindow.cpp') diff --git a/gui/ConsoleWindow.cpp b/gui/ConsoleWindow.cpp index e640d261..e7ac6008 100644 --- a/gui/ConsoleWindow.cpp +++ b/gui/ConsoleWindow.cpp @@ -78,8 +78,7 @@ void ConsoleWindow::write(QString data, MessageLevel::Enum mode) int val_bar = bar->value(); if(m_scroll_active) { - if(m_last_scroll_value > val_bar) - m_scroll_active = false; + m_scroll_active = (max_bar - val_bar) <= 1; } else { -- cgit v1.2.3 From fcb8612c10ae1bb1d2d8883a762979e9bca1f31e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 6 Jan 2014 02:52:51 +0100 Subject: Implement console window tray icon, console window hiding, better scrolling --- gui/ConsoleWindow.cpp | 117 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 91 insertions(+), 26 deletions(-) (limited to 'gui/ConsoleWindow.cpp') diff --git a/gui/ConsoleWindow.cpp b/gui/ConsoleWindow.cpp index e7ac6008..84a141ce 100644 --- a/gui/ConsoleWindow.cpp +++ b/gui/ConsoleWindow.cpp @@ -19,12 +19,14 @@ #include #include +#include #include #include #include #include "logic/net/PasteUpload.h" +#include "logic/icons/IconList.h" ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent) : QMainWindow(parent), ui(new Ui::ConsoleWindow), proc(mcproc) @@ -35,14 +37,28 @@ ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent) SLOT(write(QString, MessageLevel::Enum))); connect(mcproc, SIGNAL(ended(BaseInstance *, int, QProcess::ExitStatus)), this, SLOT(onEnded(BaseInstance *, int, QProcess::ExitStatus))); - connect(mcproc, SIGNAL(prelaunch_failed(BaseInstance*,int,QProcess::ExitStatus)), this, + connect(mcproc, SIGNAL(prelaunch_failed(BaseInstance *, int, QProcess::ExitStatus)), this, SLOT(onEnded(BaseInstance *, int, QProcess::ExitStatus))); - connect(mcproc, SIGNAL(launch_failed(BaseInstance*)), this, - SLOT(onLaunchFailed(BaseInstance*))); + connect(mcproc, SIGNAL(launch_failed(BaseInstance *)), this, + SLOT(onLaunchFailed(BaseInstance *))); - restoreState(QByteArray::fromBase64(MMC->settings()->get("ConsoleWindowState").toByteArray())); - restoreGeometry(QByteArray::fromBase64(MMC->settings()->get("ConsoleWindowGeometry").toByteArray())); + restoreState( + QByteArray::fromBase64(MMC->settings()->get("ConsoleWindowState").toByteArray())); + restoreGeometry( + QByteArray::fromBase64(MMC->settings()->get("ConsoleWindowGeometry").toByteArray())); + QString iconKey = proc->instance()->iconKey(); + QString name = proc->instance()->name(); + auto icon = MMC->icons()->getIcon(iconKey); + setWindowIcon(icon); + m_trayIcon = new QSystemTrayIcon(icon, this); + QString consoleTitle = tr("Console window for ") + name; + m_trayIcon->setToolTip(consoleTitle); + setWindowTitle(consoleTitle); + + connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), + SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); + m_trayIcon->show(); if (mcproc->instance()->settings().get("ShowConsole").toBool()) { show(); @@ -55,13 +71,26 @@ ConsoleWindow::~ConsoleWindow() delete ui; } +void ConsoleWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) +{ + switch (reason) + { + case QSystemTrayIcon::Trigger: + { + toggleConsole(); + } + default: + return; + } +} + void ConsoleWindow::writeColor(QString text, const char *color) { // append a paragraph QString newtext; newtext += "text->verticalScrollBar(); int max_bar = bar->maximum(); int val_bar = bar->value(); - if(m_scroll_active) - { - m_scroll_active = (max_bar - val_bar) <= 1; - } - else + if(isVisible()) { - m_scroll_active = val_bar == max_bar; + if (m_scroll_active) + { + m_scroll_active = (max_bar - val_bar) <= 1; + } + else + { + m_scroll_active = val_bar == max_bar; + } } - if (data.endsWith('\n')) data = data.left(data.length() - 1); QStringList paragraphs = data.split('\n'); @@ -113,11 +144,14 @@ void ConsoleWindow::write(QString data, MessageLevel::Enum mode) else while (iter.hasNext()) writeColor(iter.next()); - if(m_scroll_active) + if(isVisible()) { - bar->setValue(bar->maximum()); + if (m_scroll_active) + { + bar->setValue(bar->maximum()); + } + m_last_scroll_value = bar->value(); } - m_last_scroll_value = bar->value(); } void ConsoleWindow::clear() @@ -133,22 +167,45 @@ void ConsoleWindow::on_closeButton_clicked() void ConsoleWindow::setMayClose(bool mayclose) { m_mayclose = mayclose; - if (mayclose) - ui->closeButton->setEnabled(true); +} + +void ConsoleWindow::toggleConsole() +{ + QScrollBar *bar = ui->text->verticalScrollBar(); + if (isVisible()) + { + int max_bar = bar->maximum(); + int val_bar = m_last_scroll_value = bar->value(); + m_scroll_active = (max_bar - val_bar) <= 1; + hide(); + } else - ui->closeButton->setEnabled(false); + { + show(); + if (m_scroll_active) + { + bar->setValue(bar->maximum()); + } + else + { + bar->setValue(m_last_scroll_value); + } + } } void ConsoleWindow::closeEvent(QCloseEvent *event) { if (!m_mayclose) - event->ignore(); + { + toggleConsole(); + } else { MMC->settings()->set("ConsoleWindowState", saveState().toBase64()); MMC->settings()->set("ConsoleWindowGeometry", saveGeometry().toBase64()); emit isClosing(); + m_trayIcon->hide(); QMainWindow::closeEvent(event); } } @@ -169,19 +226,26 @@ void ConsoleWindow::on_btnKillMinecraft_clicked() void ConsoleWindow::onEnded(BaseInstance *instance, int code, QProcess::ExitStatus status) { + bool peacefulExit = code == 0 && status != QProcess::CrashExit; ui->btnKillMinecraft->setEnabled(false); setMayClose(true); if (instance->settings().get("AutoCloseConsole").toBool()) { - if (code == 0 && status != QProcess::CrashExit) + if (peacefulExit) { this->close(); return; } } - if(!isVisible()) + /* + if(!peacefulExit) + { + m_trayIcon->showMessage(tr("Oh no!"), tr("Minecraft crashed!"), QSystemTrayIcon::Critical); + } + */ + if (!isVisible()) show(); } @@ -191,7 +255,7 @@ void ConsoleWindow::onLaunchFailed(BaseInstance *instance) setMayClose(true); - if(!isVisible()) + if (!isVisible()) show(); } @@ -199,10 +263,11 @@ void ConsoleWindow::on_btnPaste_clicked() { auto text = ui->text->toPlainText(); ProgressDialog dialog(this); - PasteUpload* paste=new PasteUpload(this, text); + PasteUpload *paste = new PasteUpload(this, text); dialog.exec(paste); - if(!paste->successful()) + if (!paste->successful()) { - CustomMessageBox::selectable(this, "Upload failed", paste->failReason(), QMessageBox::Critical)->exec(); + CustomMessageBox::selectable(this, "Upload failed", paste->failReason(), + QMessageBox::Critical)->exec(); } } -- cgit v1.2.3