📄 qwsmanager_qws.cpp
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qwsmanager_qws.h"#ifndef QT_NO_QWS_MANAGER#include "qdrawutil.h"#include "qapplication.h"#include "qstyle.h"#include "qwidget.h"#include "qmenu.h"#include "qpainter.h"#include "private/qpainter_p.h"#include "qregion.h"#include "qevent.h"#include "qcursor.h"#include "qwsdisplay_qws.h"#include "qdesktopwidget.h"#include <private/qapplication_p.h>#include <private/qwidget_p.h>#include <private/qbackingstore_p.h>#include <private/qwindowsurface_qws_p.h>#include "qdecorationfactory_qws.h"#include "qlayout.h"#include "qwsmanager_p.h"#include <qdebug.h>QWidget *QWSManagerPrivate::active = 0;QPoint QWSManagerPrivate::mousePos;QWSManagerPrivate::QWSManagerPrivate() : QObjectPrivate(), activeRegion(QDecoration::None), managed(0), popup(0), previousRegionType(0), previousRegionRepainted(false){ cached_region.regionType = 0;}QRegion &QWSManager::cachedRegion(){ return d_func()->cached_region.region;}/*! \class QWSManager \ingroup qws \internal*//*!*/QWSManager::QWSManager(QWidget *w) : QObject(*new QWSManagerPrivate, (QObject*)0){ d_func()->managed = w;}QWSManager::~QWSManager(){ Q_D(QWSManager);#ifndef QT_NO_MENU if (d->popup) delete d->popup;#endif if (d->managed == QWSManagerPrivate::active) QWSManagerPrivate::active = 0;}QWidget *QWSManager::widget(){ Q_D(QWSManager); return d->managed;}QWidget *QWSManager::grabbedMouse(){ return QWSManagerPrivate::active;}QRegion QWSManager::region(){ Q_D(QWSManager); return QApplication::qwsDecoration().region(d->managed, d->managed->geometry());}bool QWSManager::event(QEvent *e){ if (QObject::event(e)) return true; switch (e->type()) { case QEvent::MouseMove: mouseMoveEvent((QMouseEvent*)e); break; case QEvent::MouseButtonPress: mousePressEvent((QMouseEvent*)e); break; case QEvent::MouseButtonRelease: mouseReleaseEvent((QMouseEvent*)e); break; case QEvent::MouseButtonDblClick: mouseDoubleClickEvent((QMouseEvent*)e); break; case QEvent::Paint: paintEvent((QPaintEvent*)e); break; default: return false; break; } return true;}void QWSManager::mousePressEvent(QMouseEvent *e){ Q_D(QWSManager); d->mousePos = e->globalPos(); d->activeRegion = QApplication::qwsDecoration().regionAt(d->managed, d->mousePos); if(d->cached_region.regionType) d->previousRegionRepainted |= repaintRegion(d->cached_region.regionType, QDecoration::Pressed); if (d->activeRegion == QDecoration::Menu) { QPoint pos = (QApplication::layoutDirection() == Qt::LeftToRight ? d->managed->geometry().topLeft() : d->managed->geometry().topRight()); menu(pos); } if (d->activeRegion != QDecoration::None && d->activeRegion != QDecoration::Menu) { d->active = d->managed; d->managed->grabMouse(); } if (d->activeRegion != QDecoration::None && d->activeRegion != QDecoration::Close && d->activeRegion != QDecoration::Minimize && d->activeRegion != QDecoration::Menu) { d->managed->raise(); } if (e->button() == Qt::RightButton) { menu(e->globalPos()); }}void QWSManager::mouseReleaseEvent(QMouseEvent *e){ Q_D(QWSManager); d->managed->releaseMouse(); if (d->cached_region.regionType && d->previousRegionRepainted && QApplication::mouseButtons() == 0) { bool doesHover = repaintRegion(d->cached_region.regionType, QDecoration::Hover); if (!doesHover) { repaintRegion(d->cached_region.regionType, QDecoration::Normal); d->previousRegionRepainted = false; } } if (e->button() == Qt::LeftButton) { //handleMove(); int itm = QApplication::qwsDecoration().regionAt(d->managed, e->globalPos()); int activatedItem = d->activeRegion; d->activeRegion = QDecoration::None; d->active = 0; if (activatedItem == itm) QApplication::qwsDecoration().regionClicked(d->managed, itm); } else if (d->activeRegion == QDecoration::None) { d->active = 0; }}void QWSManager::mouseDoubleClickEvent(QMouseEvent *e){ Q_D(QWSManager); if (e->button() == Qt::LeftButton) QApplication::qwsDecoration().regionDoubleClicked(d->managed, QApplication::qwsDecoration().regionAt(d->managed, e->globalPos()));}static inline Qt::CursorShape regionToShape(int region){ if (region == QDecoration::None) return Qt::ArrowCursor; static const struct { int region; Qt::CursorShape shape; } r2s[] = { { QDecoration::TopLeft, Qt::SizeFDiagCursor }, { QDecoration::Top, Qt::SizeVerCursor}, { QDecoration::TopRight, Qt::SizeBDiagCursor}, { QDecoration::Left, Qt::SizeHorCursor}, { QDecoration::Right, Qt::SizeHorCursor}, { QDecoration::BottomLeft, Qt::SizeBDiagCursor}, { QDecoration::Bottom, Qt::SizeVerCursor}, { QDecoration::BottomRight, Qt::SizeFDiagCursor}, { QDecoration::None, Qt::ArrowCursor} }; int i = 0; while (region != r2s[i].region && r2s[i].region) ++i; return r2s[i].shape;}void QWSManager::mouseMoveEvent(QMouseEvent *e){ Q_D(QWSManager); if (d->newCachedRegion(e->globalPos())) { if(d->previousRegionType && d->previousRegionRepainted) repaintRegion(d->previousRegionType, QDecoration::Normal); if(d->cached_region.regionType) { d->previousRegionRepainted = repaintRegion(d->cached_region.regionType, QDecoration::Hover); } }#ifndef QT_NO_CURSOR QWSDisplay *qwsd = QApplication::desktop()->qwsDisplay(); qwsd->selectCursor(d->managed, regionToShape(d->cachedRegionAt()));#endif //QT_NO_CURSOR if (d->activeRegion) handleMove(e->globalPos());}void QWSManager::handleMove(QPoint g){ Q_D(QWSManager); // don't allow dragging to where the user probably cannot click! QApplicationPrivate *ap = QApplicationPrivate::instance(); const QRect maxWindowRect = ap->maxWindowRect(qt_screen); if (maxWindowRect.isValid()) { if (g.x() < maxWindowRect.x()) g.setX(maxWindowRect.x()); if (g.y() < maxWindowRect.y()) g.setY(maxWindowRect.y()); if (g.x() > maxWindowRect.right()) g.setX(maxWindowRect.right());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -