diff --git a/src/goldendict.pro b/src/goldendict.pro index 88c8b730..e6abb69c 100644 --- a/src/goldendict.pro +++ b/src/goldendict.pro @@ -64,7 +64,6 @@ HEADERS += folding.hh \ dictlock.hh \ wordfinder.hh \ groupcombobox.hh \ - griparea.hh \ keyboardstate.hh \ mouseover.hh \ preferences.hh @@ -80,8 +79,7 @@ SOURCES += folding.cc main.cc dictionary.cc md5.c config.cc sources.cc \ dsl.cc dsl_details.cc filetype.cc fsencoding.cc groups.cc \ groups_widgets.cc instances.cc article_maker.cc scanpopup.cc \ articleview.cc externalviewer.cc dictlock.cc wordfinder.cc \ - groupcombobox.cc griparea.cc keyboardstate.cc mouseover.cc \ - preferences.cc + groupcombobox.cc keyboardstate.cc mouseover.cc preferences.cc win32 { SOURCES += mouseover_win32/ThTypes.c diff --git a/src/griparea.cc b/src/griparea.cc deleted file mode 100644 index 8b1112c9..00000000 --- a/src/griparea.cc +++ /dev/null @@ -1,53 +0,0 @@ -/* This file is (c) 2008-2009 Konstantin Isakov - * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */ - -#include "griparea.hh" -#include - -GripArea::GripArea( QWidget * parent ): QWidget( parent ) -{ - setCursor( Qt::OpenHandCursor ); -} - -void GripArea::paintEvent( QPaintEvent * ) -{ - if ( isEnabled() ) - { - QStylePainter p( this ); - - QStyleOptionDockWidgetV2 opt; - - opt.initFrom( this ); - - p.drawControl( QStyle::CE_DockWidgetTitle, opt ); - } -} - -void GripArea::mousePressEvent( QMouseEvent * ev ) -{ - startPos = ev->globalPos(); - setCursor( Qt::ClosedHandCursor ); -} - -void GripArea::mouseMoveEvent( QMouseEvent * ev ) -{ - QPoint newPos = ev->globalPos(); - - QPoint delta = newPos - startPos; - - startPos = newPos; - - // Find a top-level window - - QWidget * w = this; - - while( w && !w->isWindow() && w->windowType() != Qt::SubWindow ) - w = w->parentWidget(); - - w->move( w->pos() + delta ); -} - -void GripArea::mouseReleaseEvent( QMouseEvent * ) -{ - setCursor( Qt::OpenHandCursor ); -} diff --git a/src/griparea.hh b/src/griparea.hh deleted file mode 100644 index 2f990ccc..00000000 --- a/src/griparea.hh +++ /dev/null @@ -1,32 +0,0 @@ -/* This file is (c) 2008-2009 Konstantin Isakov - * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */ - -#ifndef __GRIPAREA_HH_INCLUDED__ -#define __GRIPAREA_HH_INCLUDED__ - -#include -#include -#include - -/// A grip area to move a window, looking like a dock widget's title area. -class GripArea: public QWidget -{ - Q_OBJECT - -public: - - GripArea( QWidget * parent ); - -protected: - - virtual void paintEvent( QPaintEvent * ); - virtual void mousePressEvent( QMouseEvent * ); - virtual void mouseMoveEvent( QMouseEvent * ); - virtual void mouseReleaseEvent( QMouseEvent * ); - -private: - - QPoint startPos; -}; - -#endif diff --git a/src/scanpopup.cc b/src/scanpopup.cc index bf9cb422..d90abed7 100644 --- a/src/scanpopup.cc +++ b/src/scanpopup.cc @@ -158,9 +158,30 @@ vector< sptr< Dictionary::Class > > const & ScanPopup::getActiveDicts() groups[ currentGroup ].dictionaries; } +void ScanPopup::mousePressEvent( QMouseEvent * ev ) +{ + startPos = ev->globalPos(); + setCursor( Qt::ClosedHandCursor ); + + QDialog::mousePressEvent( ev ); +} + void ScanPopup::mouseMoveEvent( QMouseEvent * event ) { + if ( event->buttons() ) + { + QPoint newPos = event->globalPos(); + + QPoint delta = newPos - startPos; + + startPos = newPos; + + // Find a top-level window + + move( pos() + delta ); + } #ifdef Q_OS_WIN32 + else if ( !ui.pinButton->isChecked() ) { if ( !mouseEnteredOnce ) @@ -184,6 +205,12 @@ void ScanPopup::mouseMoveEvent( QMouseEvent * event ) QDialog::mouseMoveEvent( event ); } +void ScanPopup::mouseReleaseEvent( QMouseEvent * ev ) +{ + unsetCursor(); + QDialog::mouseReleaseEvent( ev ); +} + void ScanPopup::leaveEvent( QEvent * event ) { QDialog::leaveEvent( event ); @@ -193,9 +220,15 @@ void ScanPopup::leaveEvent( QEvent * event ) // Combo-boxes seem to generate leave events for their parents when // unfolded, so we check coordinates as well. - // If the dialog is pinned, we don't hide the popup - if ( !ui.pinButton->isChecked() && !geometry().contains( QCursor::pos() ) ) + // If the dialog is pinned, we don't hide the popup. + // If some mouse buttons are pressed, we don't hide the popup either, + // since it indicates the move operation is underway. + if ( !ui.pinButton->isChecked() && !geometry().contains( QCursor::pos() ) && + QApplication::mouseButtons() == Qt::NoButton ) + { + unsetCursor(); // Just in case hide(); + } } void ScanPopup::resizeEvent( QResizeEvent * event ) diff --git a/src/scanpopup.hh b/src/scanpopup.hh index 99dd8fab..7e12e7ec 100644 --- a/src/scanpopup.hh +++ b/src/scanpopup.hh @@ -41,12 +41,16 @@ private: bool mouseEnteredOnce; + QPoint startPos; // For window moving + void handleInputWord( QString const & ); void initiateTranslation(); vector< sptr< Dictionary::Class > > const & getActiveDicts(); - virtual void mouseMoveEvent( QMouseEvent * event ); + virtual void mousePressEvent( QMouseEvent * ); + virtual void mouseMoveEvent( QMouseEvent * ); + virtual void mouseReleaseEvent( QMouseEvent * ); virtual void leaveEvent( QEvent * event ); virtual void resizeEvent( QResizeEvent * event ); diff --git a/src/scanpopup.ui b/src/scanpopup.ui index 11373f36..f5fc3e82 100644 --- a/src/scanpopup.ui +++ b/src/scanpopup.ui @@ -91,14 +91,17 @@ - - - - 0 - 0 - + + + Qt::Horizontal - + + + 40 + 20 + + + @@ -130,12 +133,6 @@ QComboBox
groupcombobox.hh
- - GripArea - QWidget -
griparea.hh
- 1 -