mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
+ Smart placement of the popup window implemented.
This commit is contained in:
parent
d32fd02217
commit
c23e1351f4
|
@ -10,6 +10,7 @@
|
|||
#include <QBitmap>
|
||||
#include <QMenu>
|
||||
#include <QMouseEvent>
|
||||
#include <QDesktopWidget>
|
||||
|
||||
using std::wstring;
|
||||
|
||||
|
@ -116,15 +117,46 @@ void ScanPopup::handleInputWord( QString const & str )
|
|||
|
||||
if ( !isVisible() )
|
||||
{
|
||||
// Decide where should the window land
|
||||
|
||||
QPoint currentPos = QCursor::pos();
|
||||
|
||||
move( currentPos.x() + 4, currentPos.y() + 10 );
|
||||
QRect desktop = QApplication::desktop()->screenGeometry();
|
||||
|
||||
QSize windowSize = geometry().size();
|
||||
|
||||
int x, y;
|
||||
|
||||
/// Try the to-the-right placement
|
||||
if ( currentPos.x() + 4 + windowSize.width() <= desktop.topRight().x() )
|
||||
x = currentPos.x() + 4;
|
||||
else
|
||||
/// Try the to-the-left placement
|
||||
if ( currentPos.x() - 4 - windowSize.width() >= desktop.x() )
|
||||
x = currentPos.x() - 4 - windowSize.width();
|
||||
else
|
||||
// Center it
|
||||
x = desktop.x() + ( desktop.width() - windowSize.width() ) / 2;
|
||||
|
||||
/// Try the to-the-buttom placement
|
||||
if ( currentPos.y() + 15 + windowSize.height() <= desktop.bottomLeft().y() )
|
||||
y = currentPos.y() + 15;
|
||||
else
|
||||
/// Try the to-the-top placement
|
||||
if ( currentPos.y() - 15 - windowSize.height() >= desktop.y() )
|
||||
y = currentPos.y() - 15 - windowSize.height();
|
||||
else
|
||||
// Center it
|
||||
y = desktop.y() + ( desktop.height() - windowSize.height() ) / 2;
|
||||
|
||||
move( x, y );
|
||||
|
||||
show();
|
||||
|
||||
mouseEnteredOnce = false; // Windows-only
|
||||
|
||||
QApplication::processEvents(); // Make window appear immediately no matter what
|
||||
// This produced some funky mouse grip-related bugs so we commented it out
|
||||
//QApplication::processEvents(); // Make window appear immediately no matter what
|
||||
}
|
||||
|
||||
initiateTranslation();
|
||||
|
|
Loading…
Reference in a new issue