mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
* Make the popup window itself be movable; fix the associated with the gripping
and moving problems.
This commit is contained in:
parent
12c49065e5
commit
61943519c1
|
@ -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
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
/* This file is (c) 2008-2009 Konstantin Isakov <ikm@users.berlios.de>
|
||||
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
||||
|
||||
#include "griparea.hh"
|
||||
#include <QMouseEvent>
|
||||
|
||||
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 );
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
/* This file is (c) 2008-2009 Konstantin Isakov <ikm@users.berlios.de>
|
||||
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
||||
|
||||
#ifndef __GRIPAREA_HH_INCLUDED__
|
||||
#define __GRIPAREA_HH_INCLUDED__
|
||||
|
||||
#include <QWidget>
|
||||
#include <QStylePainter>
|
||||
#include <QStyleOptionDockWidget>
|
||||
|
||||
/// 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
|
|
@ -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,10 +220,16 @@ 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 )
|
||||
{
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -91,14 +91,17 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="GripArea" name="gripArea" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="pinButton">
|
||||
|
@ -130,12 +133,6 @@
|
|||
<extends>QComboBox</extends>
|
||||
<header>groupcombobox.hh</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>GripArea</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>griparea.hh</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="resources.qrc"/>
|
||||
|
|
Loading…
Reference in a new issue