-
Notifications
You must be signed in to change notification settings - Fork 0
/
menuapplications.cpp
executable file
·135 lines (99 loc) · 3.16 KB
/
menuapplications.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "menuapplications.h"
#include "utils/mystyle.h"
#include "utils/desktopfile.h"
//#include "utils/x11utills.h"
#include <QDesktopWidget>
#include <QDebug>
#include<QSettings>
#define Classic_Menu 0
#define Form_Menu 1
//------------------------------------------------------------------
MenuApplications::MenuApplications(QObject *parent) :
QObject(parent),menuStyle(0),/*mMenuForm(0),*/mMenuClassic(0),mX(0),mY(0)
{
// qDebug()<<"aime here-----------";
QApplication::setAttribute(Qt::AA_DontShowIconsInMenus ,false);
mFileSystemWatcher=new QFileSystemWatcher;
QSettings setting;
mFileSystemWatcher->addPath(setting.fileName());
connect(mFileSystemWatcher,SIGNAL(fileChanged(QString)),this,SLOT(loadSettings()));
loadSettings();
if(menuStyle==Classic_Menu){
mMenuClassic=new MenuClassic;
} else{
// mMenuForm=new MenuForm;
}
}
void MenuApplications::showForm()
{
// if(mMenuForm)
// mMenuForm->open(QCursor::pos(),0);
}
//------------------------------------------------------------------
void MenuApplications::loadSettings()
{
QSettings setting;
// MenuStyle 0=classic 1=formMenu Default=0
menuStyle=setting.value("MenuStyle",0).toInt();
//MenuPos position of menu
//0= cursorPos 1=topLeft 2=topRight 3=botLeft 4=botRight Default =0
menuPos=setting.value("MenuPos",0).toInt();
//
mX=setting.value("At-X",0).toInt();
mY=setting.value("At-Y",0).toInt();
}
//------------------------------------------------------------------
void MenuApplications::afterMenuActivated()
{
QPoint mpos=QCursor::pos();
QRect screen = QApplication::desktop()->availableGeometry(mpos);
int h=mMenuClassic->height();
int w=mMenuClassic->width();
switch (menuPos) {
case 1:
mpos=screen.topLeft()+QPoint(mX,mY);
break;
case 2:
mpos=QPoint(screen.right()-w-mX,screen.top()+mY);
break;
case 3:
mpos=QPoint(screen.left()+mX,screen.bottom()-h-mY);
break;
case 4:
mpos=QPoint(screen.right()-w-mX,screen.bottom()-h-mY);
break;
default:
mpos=QCursor::pos()+QPoint(mX,mY);
break;
}
qDebug()<<mpos;
if(menuStyle==Classic_Menu){
if(!mMenuClassic)return;
mMenuClassic->popup(mpos);
qDebug()<<"pos2"<< mMenuClassic->pos();
//mMenuClassic->showTearOffMenu(mpos);
mMenuClassic->activateWindow();
// X11UTILLS::raiseWindow(mMenuClassic->winId());
mMenuClassic->setFocus();
}else{
// if(!mMenuForm)return;
// showForm();
// mMenuForm->setFocus();
}
}
//------------------------------------------------------------------
void MenuApplications::showMenu()
{
if(menuStyle==Classic_Menu){
if(!mMenuClassic)return;
mMenuClassic->show();
mMenuClassic->activateWindow();
mMenuClassic->setFocus();
mMenuClassic->hide();
}else{
// if(!mMenuForm)return;
// mMenuForm ->activateWindow();
// mMenuForm->setFocus();
}
QTimer::singleShot(10, this, SLOT(afterMenuActivated()));
}