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
|
#include <QtGui>
#include "desktop.h"
#include <iostream>
#include <QDesktopWidget>
#include <QEvent>
#include <QPoint>
#include <Qt>
#include <QWidget>
#include<QCursor>
#include<QRect>
Desktop::Desktop()
{
QDesktopWidget *widget = new QDesktopWidget;
x = widget->primaryScreen();
rect1 = widget->availableGeometry ( x );
rect1.setY(rect1.top()/2);
createActions();
}
void Desktop::mouseMoveEvent ( QMouseEvent * event )
{
QPoint test = QCursor::pos();
if (rect1.contains( test, false ) )
{
QMenu menu(this);
menu.addAction(cutAct);
menu.addAction(copyAct);
menu.addAction(pasteAct);
menu.exec(QCursor::pos());
}
}
void Desktop::cut()
{
infoLabel->setText(tr("Invoked <b>Edit|Cut</b>"));
}
void Desktop::copy()
{
infoLabel->setText(tr("Invoked <b>Edit|Copy</b>"));
}
void Desktop::paste()
{
infoLabel->setText(tr("Invoked <b>Edit|Paste</b>"));
}
void Desktop::createActions()
{
cutAct = new QAction(tr("Cu&t"), this);
cutAct->setShortcut(tr("Ctrl+X"));
cutAct->setStatusTip(tr("Cut the current selection's contents to the "
"clipboard"));
connect(cutAct, SIGNAL(triggered()), this, SLOT(cut()));
copyAct = new QAction(tr("&Copy"), this);
copyAct->setShortcut(tr("Ctrl+C"));
copyAct->setStatusTip(tr("Copy the current selection's contents to the "
"clipboard"));
connect(copyAct, SIGNAL(triggered()), this, SLOT(copy()));
pasteAct = new QAction(tr("&Paste"), this);
pasteAct->setShortcut(tr("Ctrl+V"));
pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current "
"selection"));
connect(pasteAct, SIGNAL(triggered()), this, SLOT(paste()));
} |
Partager