mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14: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 \
|
dictlock.hh \
|
||||||
wordfinder.hh \
|
wordfinder.hh \
|
||||||
groupcombobox.hh \
|
groupcombobox.hh \
|
||||||
griparea.hh \
|
|
||||||
keyboardstate.hh \
|
keyboardstate.hh \
|
||||||
mouseover.hh \
|
mouseover.hh \
|
||||||
preferences.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 \
|
dsl.cc dsl_details.cc filetype.cc fsencoding.cc groups.cc \
|
||||||
groups_widgets.cc instances.cc article_maker.cc scanpopup.cc \
|
groups_widgets.cc instances.cc article_maker.cc scanpopup.cc \
|
||||||
articleview.cc externalviewer.cc dictlock.cc wordfinder.cc \
|
articleview.cc externalviewer.cc dictlock.cc wordfinder.cc \
|
||||||
groupcombobox.cc griparea.cc keyboardstate.cc mouseover.cc \
|
groupcombobox.cc keyboardstate.cc mouseover.cc preferences.cc
|
||||||
preferences.cc
|
|
||||||
|
|
||||||
win32 {
|
win32 {
|
||||||
SOURCES += mouseover_win32/ThTypes.c
|
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;
|
groups[ currentGroup ].dictionaries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScanPopup::mousePressEvent( QMouseEvent * ev )
|
||||||
|
{
|
||||||
|
startPos = ev->globalPos();
|
||||||
|
setCursor( Qt::ClosedHandCursor );
|
||||||
|
|
||||||
|
QDialog::mousePressEvent( ev );
|
||||||
|
}
|
||||||
|
|
||||||
void ScanPopup::mouseMoveEvent( QMouseEvent * event )
|
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
|
#ifdef Q_OS_WIN32
|
||||||
|
else
|
||||||
if ( !ui.pinButton->isChecked() )
|
if ( !ui.pinButton->isChecked() )
|
||||||
{
|
{
|
||||||
if ( !mouseEnteredOnce )
|
if ( !mouseEnteredOnce )
|
||||||
|
@ -184,6 +205,12 @@ void ScanPopup::mouseMoveEvent( QMouseEvent * event )
|
||||||
QDialog::mouseMoveEvent( event );
|
QDialog::mouseMoveEvent( event );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScanPopup::mouseReleaseEvent( QMouseEvent * ev )
|
||||||
|
{
|
||||||
|
unsetCursor();
|
||||||
|
QDialog::mouseReleaseEvent( ev );
|
||||||
|
}
|
||||||
|
|
||||||
void ScanPopup::leaveEvent( QEvent * event )
|
void ScanPopup::leaveEvent( QEvent * event )
|
||||||
{
|
{
|
||||||
QDialog::leaveEvent( event );
|
QDialog::leaveEvent( event );
|
||||||
|
@ -193,9 +220,15 @@ void ScanPopup::leaveEvent( QEvent * event )
|
||||||
|
|
||||||
// Combo-boxes seem to generate leave events for their parents when
|
// Combo-boxes seem to generate leave events for their parents when
|
||||||
// unfolded, so we check coordinates as well.
|
// unfolded, so we check coordinates as well.
|
||||||
// If the dialog is pinned, we don't hide the popup
|
// If the dialog is pinned, we don't hide the popup.
|
||||||
if ( !ui.pinButton->isChecked() && !geometry().contains( QCursor::pos() ) )
|
// 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();
|
hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScanPopup::resizeEvent( QResizeEvent * event )
|
void ScanPopup::resizeEvent( QResizeEvent * event )
|
||||||
|
|
|
@ -41,12 +41,16 @@ private:
|
||||||
|
|
||||||
bool mouseEnteredOnce;
|
bool mouseEnteredOnce;
|
||||||
|
|
||||||
|
QPoint startPos; // For window moving
|
||||||
|
|
||||||
void handleInputWord( QString const & );
|
void handleInputWord( QString const & );
|
||||||
void initiateTranslation();
|
void initiateTranslation();
|
||||||
|
|
||||||
vector< sptr< Dictionary::Class > > const & getActiveDicts();
|
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 leaveEvent( QEvent * event );
|
||||||
virtual void resizeEvent( QResizeEvent * event );
|
virtual void resizeEvent( QResizeEvent * event );
|
||||||
|
|
||||||
|
|
|
@ -91,14 +91,17 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="GripArea" name="gripArea" native="true">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="sizePolicy">
|
<property name="orientation">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
<enum>Qt::Horizontal</enum>
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="pinButton">
|
<widget class="QToolButton" name="pinButton">
|
||||||
|
@ -130,12 +133,6 @@
|
||||||
<extends>QComboBox</extends>
|
<extends>QComboBox</extends>
|
||||||
<header>groupcombobox.hh</header>
|
<header>groupcombobox.hh</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
|
||||||
<class>GripArea</class>
|
|
||||||
<extends>QWidget</extends>
|
|
||||||
<header>griparea.hh</header>
|
|
||||||
<container>1</container>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="resources.qrc"/>
|
<include location="resources.qrc"/>
|
||||||
|
|
Loading…
Reference in a new issue