]>
cloud.milkyroute.net Git - dolphin.git/blob - src/tagcloud/taggingpopup.cpp
3e59c80d1a584ff2c748d8757ecd420674ce186a
2 This file is part of the Nepomuk KDE project.
3 Copyright (C) 2007 Sebastian Trueg <trueg@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "taggingpopup.h"
22 #include <QtCore/QEventLoop>
23 #include <QtCore/QPointer>
24 #include <QtGui/QApplication>
25 #include <QtGui/QDesktopWidget>
26 #include <QtGui/QMouseEvent>
32 class Nepomuk::TaggingPopup::Private
35 Private( TaggingPopup
* parent
)
40 QEventLoop
* eventLoop
;
43 QRect
geometryForPopupPos( const QPoint
& p
) {
44 QSize size
= m_parent
->sizeHint();
46 // we want a little margin
47 const int margin
= KDialog::marginHint();
48 size
.setHeight( size
.height() + margin
*2 );
49 size
.setWidth( size
.width() + margin
*2 );
51 QRect screen
= QApplication::desktop()->screenGeometry( QApplication::desktop()->screenNumber( p
) );
53 // calculate popup position
54 QPoint
pos( p
.x() - size
.width()/2, p
.y() - size
.height()/2 );
56 // ensure we do not leave the desktop
57 if ( pos
.x() + size
.width() > screen
.right() ) {
58 pos
.setX( screen
.right() - size
.width() );
60 else if ( pos
.x() < screen
.left() ) {
61 pos
.setX( screen
.left() );
64 if ( pos
.y() + size
.height() > screen
.bottom() ) {
65 pos
.setY( screen
.bottom() - size
.height() );
67 else if ( pos
.y() < screen
.top() ) {
68 pos
.setY( screen
.top() );
71 return QRect( pos
, size
);
75 TaggingPopup
* m_parent
;
79 Nepomuk::TaggingPopup::TaggingPopup( QWidget
* parent
)
81 d( new Private( this ) )
83 setFrameStyle( QFrame::Box
|QFrame::Plain
);
84 setWindowFlags( Qt::Popup
);
88 Nepomuk::TaggingPopup::~TaggingPopup()
94 void Nepomuk::TaggingPopup::popup( const QPoint
& p
)
96 setGeometry( d
->geometryForPopupPos( p
) );
103 void Nepomuk::TaggingPopup::exec( const QPoint
& pos
)
105 QEventLoop eventLoop
;
106 d
->eventLoop
= &eventLoop
;
109 QPointer
<QObject
> guard
= this;
110 (void) eventLoop
.exec();
111 if ( !guard
.isNull() )
116 void Nepomuk::TaggingPopup::mousePressEvent( QMouseEvent
* e
)
118 if ( !rect().contains( e
->pos() ) ) {
122 TagCloud::mousePressEvent( e
);
127 void Nepomuk::TaggingPopup::hideEvent( QHideEvent
* e
)
130 if ( d
->eventLoop
) {
131 d
->eventLoop
->exit();
136 bool Nepomuk::TaggingPopup::event( QEvent
* e
)
138 if ( e
->type() == QEvent::LayoutRequest
) {
140 setGeometry( d
->geometryForPopupPos( d
->popupPos
) );
145 return TagCloud::event( e
);