This repository has been archived on 2021-01-14. You can view files and clone it, but cannot push or open issues or pull requests.
Passgen/boss.cpp

83 lines
2.7 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "boss.h"
#include <QtGui>
boss::boss(QWidget *parent)
: QMainWindow(parent)
{
cnm = new conmenu();
trayIco = new QSystemTrayIcon(this);
connect(trayIco, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(ia(QSystemTrayIcon::ActivationReason)));
QIcon temp = QIcon(":/lock.png");
trayIco->setIcon(temp);
trayIco->show();
}
/**
подмена внешнего вида контекс меню
* @brief boss::ttt
*/
void boss::ttt()
{
cnm->close();
QRect *gg = mcm();
cnm->move(gg->x(),gg->y());
cnm->show();
}
/**
Обработка действий с менюхой
* @brief boss::ia
* @param reason
*/
void boss::ia(QSystemTrayIcon::ActivationReason reason)
{
switch(reason)
{
case QSystemTrayIcon::Context:
ttt();
break;
default:
break;
}
}
boss::~boss()
{
}
/**
* @brief boss::mcm
* @return позицию иконки в трее (x,y,width,height)
*/
QRect *boss::mcm()
{
int sw, sh;//разрешение
int ew, eh;//размеры менюхи
int tx, ty;//позиция иконки в трее
QRect sg = QGuiApplication::primaryScreen()->geometry();
sw = sg.width(); sh = sg.height();//длина и ширина разришения
ew = cnm->width(); eh = cnm->height();//длина и ширина менюхи
QRect ss = trayIco->geometry();
tx = ss.x(); ty = ss.y();//позиция иконки
QRect *temp = new QRect(0,0,0,0);
int px = 30;
temp->setX(((tx-ew-px)<0) ? (tx+px) : (tx-ew-px));//если менюха по x пойдет слишком влево(за пределы) то двигаем вправо если нет то пускай так и будет
temp->setX(((tx+px+ew)>sw) ? (tx-ew-px) : (tx+px));//если ненюха но x будет уходить вправо(за пределы) то двигаем влево на всю длинну ели нет то так и будет
/*
*30 является неким отступом
* размеры менюхи задаються в conmenu.cpp на 48 строке **resize(200,500)
* 1) например if tx(15)-ew(200)-30<0 then tx(15)+30 else tx(15)-ew(200)-30 для случаев с левостроронним треем
* 2)например if tx(1000)+30+ew(200)>sw(1024) then tx(1000)-ew(200)-30 else tx(1000)+30 для случеев с правостороним треем
*/
int py = 0;
#ifdef Q_OS_WIN
py = 5;
#endif
temp->setY(((ty+eh)>sh) ? (ty-eh-py) : (ty+py));//если трей слишком внизу то подымаем вверх или пускай так и будет
return temp;
}