You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.1 KiB
83 lines
2.1 KiB
#include "mainwindow.h" |
|
#include "channellist.h" |
|
#include "messagelist.h" |
|
#include "accountlist.h" |
|
#include <QSplitter> |
|
#include <QCloseEvent> |
|
#include <QApplication> |
|
#include <QStyle> |
|
|
|
MainWindow::MainWindow(QWidget *parent) |
|
: QMainWindow(parent) |
|
, m_channelList(nullptr) |
|
, m_messageList(nullptr) |
|
, m_accountList(nullptr) |
|
, m_trayIcon(nullptr) |
|
, m_trayMenu(nullptr) |
|
{ |
|
setWindowTitle("Chat"); |
|
resize(900, 600); |
|
|
|
setupUi(); |
|
setupTray(); |
|
} |
|
|
|
void MainWindow::setupUi() { |
|
auto *splitter = new QSplitter(Qt::Horizontal, this); |
|
|
|
m_channelList = new ChannelList(splitter); |
|
m_messageList = new MessageList(splitter); |
|
m_accountList = new AccountList(splitter); |
|
|
|
splitter->addWidget(m_channelList); |
|
splitter->addWidget(m_messageList); |
|
splitter->addWidget(m_accountList); |
|
|
|
splitter->setStretchFactor(0, 2); |
|
splitter->setStretchFactor(1, 5); |
|
splitter->setStretchFactor(2, 1); |
|
|
|
splitter->setSizes({220, 480, 180}); |
|
|
|
setCentralWidget(splitter); |
|
} |
|
|
|
void MainWindow::setupTray() { |
|
m_trayIcon = new QSystemTrayIcon(this); |
|
m_trayIcon->setIcon(style()->standardIcon(QStyle::SP_ComputerIcon)); |
|
m_trayIcon->setToolTip("Chat"); |
|
|
|
m_trayMenu = new QMenu(this); |
|
QAction *showAction = m_trayMenu->addAction("Show"); |
|
connect(showAction, &QAction::triggered, this, [this]() { |
|
show(); |
|
raise(); |
|
activateWindow(); |
|
}); |
|
|
|
QAction *quitAction = m_trayMenu->addAction("Quit"); |
|
connect(quitAction, &QAction::triggered, qApp, &QApplication::quit); |
|
|
|
m_trayIcon->setContextMenu(m_trayMenu); |
|
|
|
connect(m_trayIcon, &QSystemTrayIcon::activated, |
|
this, &MainWindow::onTrayActivated); |
|
|
|
m_trayIcon->show(); |
|
} |
|
|
|
void MainWindow::closeEvent(QCloseEvent *event) { |
|
hide(); |
|
m_trayIcon->showMessage("Chat", "Application minimized to tray.", |
|
QSystemTrayIcon::Information, 2000); |
|
event->ignore(); |
|
} |
|
|
|
void MainWindow::onTrayActivated(QSystemTrayIcon::ActivationReason reason) { |
|
if (reason == QSystemTrayIcon::Trigger || |
|
reason == QSystemTrayIcon::DoubleClick) { |
|
show(); |
|
raise(); |
|
activateWindow(); |
|
} |
|
}
|
|
|