2017-06-05 13:15:38 +00:00
|
|
|
#include "scanflag.hh"
|
2023-02-22 00:45:09 +00:00
|
|
|
#include <QCursor>
|
|
|
|
#include <QGuiApplication>
|
2022-01-08 13:16:22 +00:00
|
|
|
#include <QScreen>
|
2017-06-05 13:15:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
ScanFlag::ScanFlag( QWidget * parent ):
|
2023-02-22 00:45:09 +00:00
|
|
|
QMainWindow( parent ),
|
|
|
|
pushButton( new QPushButton( this ) )
|
2017-06-05 13:15:38 +00:00
|
|
|
{
|
2023-02-22 00:45:09 +00:00
|
|
|
|
|
|
|
pushButton->setIcon( QIcon( ":/icons/programicon.png" ) );
|
|
|
|
|
|
|
|
setCentralWidget( pushButton );
|
|
|
|
|
|
|
|
setFixedSize( 30, 30 );
|
2017-06-05 13:15:38 +00:00
|
|
|
|
2022-11-20 06:19:27 +00:00
|
|
|
setWindowFlags( Qt::ToolTip | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::WindowDoesNotAcceptFocus );
|
2017-06-05 13:15:38 +00:00
|
|
|
|
2023-02-22 00:45:09 +00:00
|
|
|
|
|
|
|
setAttribute( Qt::WA_TranslucentBackground );
|
2017-06-05 13:15:38 +00:00
|
|
|
setAttribute( Qt::WA_X11DoNotAcceptFocus );
|
|
|
|
|
|
|
|
hideTimer.setSingleShot( true );
|
2022-11-20 06:19:27 +00:00
|
|
|
hideTimer.setInterval( 1000 );
|
2017-06-05 13:15:38 +00:00
|
|
|
|
2023-02-22 00:45:09 +00:00
|
|
|
connect( &hideTimer, &QTimer::timeout, this, &ScanFlag::hideWindow );
|
|
|
|
connect( pushButton, &QPushButton::clicked, this, &ScanFlag::pushButtonClicked );
|
2017-06-05 13:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScanFlag::pushButtonClicked()
|
|
|
|
{
|
|
|
|
hideTimer.stop();
|
|
|
|
hide();
|
2022-11-20 06:19:27 +00:00
|
|
|
emit requestScanPopup();
|
2017-06-05 13:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScanFlag::hideWindow()
|
|
|
|
{
|
|
|
|
if ( isVisible() )
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScanFlag::showScanFlag()
|
|
|
|
{
|
|
|
|
if ( isVisible() )
|
|
|
|
hide();
|
|
|
|
|
|
|
|
QPoint currentPos = QCursor::pos();
|
|
|
|
|
2023-05-13 12:05:47 +00:00
|
|
|
auto screen = QGuiApplication::screenAt( currentPos );
|
|
|
|
if ( !screen )
|
|
|
|
return;
|
|
|
|
|
|
|
|
QRect desktop = screen->geometry();
|
2017-06-05 13:15:38 +00:00
|
|
|
|
|
|
|
QSize windowSize = geometry().size();
|
|
|
|
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
/// Try the to-the-right placement
|
2023-05-13 14:06:36 +00:00
|
|
|
if ( currentPos.x() + 4 + windowSize.width() <= desktop.topRight().x() ) {
|
2017-06-05 13:15:38 +00:00
|
|
|
x = currentPos.x() + 4;
|
2023-05-13 14:06:36 +00:00
|
|
|
}
|
|
|
|
else if ( currentPos.x() - 4 - windowSize.width() >= desktop.x() ) {
|
|
|
|
/// Try the to-the-left placement
|
2017-06-05 13:15:38 +00:00
|
|
|
x = currentPos.x() - 4 - windowSize.width();
|
2023-05-13 14:06:36 +00:00
|
|
|
}
|
|
|
|
else { // Center it
|
2017-06-05 13:15:38 +00:00
|
|
|
x = desktop.x() + ( desktop.width() - windowSize.width() ) / 2;
|
2023-05-13 14:06:36 +00:00
|
|
|
}
|
2017-06-05 13:15:38 +00:00
|
|
|
|
|
|
|
/// Try the to-the-top placement
|
2023-05-13 14:06:36 +00:00
|
|
|
if ( currentPos.y() - 15 - windowSize.height() >= desktop.y() ) {
|
2017-06-05 13:15:38 +00:00
|
|
|
y = currentPos.y() - 15 - windowSize.height();
|
2023-05-13 14:06:36 +00:00
|
|
|
}
|
|
|
|
else if ( currentPos.y() + 15 + windowSize.height() <= desktop.bottomLeft().y() ) {
|
|
|
|
/// Try the to-the-bottom placement
|
2017-06-05 13:15:38 +00:00
|
|
|
y = currentPos.y() + 15;
|
2023-05-13 14:06:36 +00:00
|
|
|
}
|
|
|
|
else { // Center it
|
2017-06-05 13:15:38 +00:00
|
|
|
y = desktop.y() + ( desktop.height() - windowSize.height() ) / 2;
|
2023-05-13 14:06:36 +00:00
|
|
|
}
|
2017-06-05 13:15:38 +00:00
|
|
|
|
|
|
|
move( x, y );
|
|
|
|
|
|
|
|
show();
|
|
|
|
hideTimer.start();
|
|
|
|
}
|