#include "mainapp.h" #include "mainwindow.h" #include #include "ishowview.h" #include "ishowframe.h" #include #include #include "login/widgetLogon.h" #include "dragproxy.h" #include #include #include #include #include #include "ui_main.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { #ifndef Q_OS_MAC QApplication::setWindowIcon(QIcon(":icons/ishow")); setWindowIcon(QIcon(":icons/ishow")); #else setUnifiedTitleAndToolBarOnMac(true); QApplication::setAttribute(Qt::AA_DontShowIconsInMenus); #endif //this->installEventFilter(this); this->resize(1002, 702); this->setMinimumSize(1002, 702); //setWindowFlags( Qt::FramelessWindowHint); this->setWindowFlags(Qt::FramelessWindowHint|Qt::WindowSystemMenuHint); this->setMouseTracking(true); this->setWindowTitle("viptalk"); iShowFrame = new IShowFrame(this); setCentralWidget(iShowFrame); DragProxy *dragproxy = new DragProxy(this); dragproxy->SetBorderWidth(4, 4, 4, 4); createActions(); createTrayIcon(); createTrayIconMenu(); } MainWindow::~MainWindow() { } bool MainWindow::addIShow(const QString& name) { return iShowFrame->addIShow(name); return false; } bool MainWindow::setCurrentIShow(const QString& name) { return iShowFrame->setCurrentIShow(name); } void MainWindow::removeAllIShows() { iShowFrame->removeAllIShows(); } void MainWindow::createActions() { QActionGroup *tabGroup = new QActionGroup(this); overviewAction = new QAction(QIcon(":/icons/overview"), tr("&Overview"), this); overviewAction->setStatusTip(tr("Show general overview of wallet")); overviewAction->setToolTip(overviewAction->statusTip()); overviewAction->setCheckable(true); overviewAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_1)); tabGroup->addAction(overviewAction); connect(overviewAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(overviewAction, SIGNAL(triggered()), this, SLOT(gotoOverviewPage())); quitAction = new QAction(QIcon(":/icons/quit"), tr("E&xit "), this); quitAction->setStatusTip(tr("Quit application")); // quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q)); // quitAction->setMenuRole(QAction::QuitRole); toggleHideAction = new QAction(QIcon(":/icons/bitcoin"), tr("&Show / Hide"), this); toggleHideAction->setStatusTip(tr("Show or hide the main Window")); toggleHideAction->setIcon(QIcon(":/icons/toolbar_testnet")); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(toggleHideAction, SIGNAL(triggered()), this, SLOT(toggleHidden())); } void MainWindow::createTrayIcon() { #ifndef Q_OS_MAC trayIcon = new QSystemTrayIcon(this); trayIcon->setToolTip(tr("viptalk")); trayIcon->setIcon(QIcon(":Images/logo/feitalk.ico")); trayIcon->show(); #endif } void MainWindow::createTrayIconMenu() { QMenu *trayIconMenu; // return if trayIcon is unset (only on non-Mac OSes) if (!trayIcon) return; trayIconMenu = new QMenu(this); trayIcon->setContextMenu(trayIconMenu); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason))); trayIconMenu->addAction(quitAction); } void MainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason) { if(reason == QSystemTrayIcon::Trigger && isLoginSuccess) { // Click on system tray icon triggers show/hide of the main window toggleHideAction->trigger(); this->show(); } } void MainWindow::saveWindowGeometry() { QSettings settings; settings.setValue("nWindowPos", pos()); settings.setValue("nWindowSize", size()); } void MainWindow::restoreWindowGeometry() { QSettings settings; QPoint pos = settings.value("nWindowPos").toPoint(); QSize size = settings.value("nWindowSize", QSize(850, 550)).toSize(); if (!pos.x() && !pos.y()) { QRect screen = QApplication::desktop()->screenGeometry(); pos.setX((screen.width()-size.width())/2); pos.setY((screen.height()-size.height())/2); } resize(size); move(pos); } void MainWindow::resizeEvent(QResizeEvent *size) { iShowFrame->setGeometry(1, 1, this->width()-2,this->height()-2); size->accept(); QMainWindow::resizeEvent(size); } void MainWindow::paintEvent(QPaintEvent *) { QPainterPath path; path.setFillRule(Qt::WindingFill); int cut = 1; path.addRect(cut, cut, this->width()-cut*2, this->height()-cut*2); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); painter.fillPath(path, QBrush(Qt::white)); QColor color("#d9d9d9"); for(int i=0; iwidth()-(cut-i)*2, this->height()-(cut-i)*2); color.setAlpha(150 - qSqrt(i)*50); painter.setPen(color); painter.drawPath(path); } }