#include "TransparentPanel.h"
#ifndef VERBOSE
#define VERBOSE 1
#endif
#include <QPainter>
#include <QMouseEvent>
#include <QApplication>
#include <QDesktopWidget>
#include <QScreen>
#include <QDebug>
// ============================================================================
TransparentPanel
::TransparentPanel( QWidget* parent
)// ============================================================================
{
setMinimumSize(10,10);
setAutoFillBackground( false );
//setAttribute( Qt::WA_OpaquePaintEvent );
setAttribute( Qt::WA_NoSystemBackground );
//setAttribute( Qt::WA_TranslucentBackground );
setUpdatesEnabled( true );
//MMDebug("TransparentPanel::TransparentPanel()\n")
//MMDebug("QApplication::desktop()->winId() = %x\n", (void*)QApplication::desktop()->winId() )
//MMDebug("GetDesktopWindow() = %x\n", (void*)GetDesktopWindow() )
updateBG();
}
// ============================================================================
TransparentPanel::~TransparentPanel()
// ============================================================================
{
//MMDebug("TransparentPanel::~TransparentPanel()\n")
}
// ============================================================================
void TransparentPanel
::paintEvent( QPaintEvent* event
) // ============================================================================
{
if (!isVisible())
return;
//MMDebug("TransparentPanel::paintEvent()\n")
dc.
setRenderHint( QPainter::NonCosmeticDefaultPen );
//dc.fillRect( rect(), Qt::white);
if (!mBG.isNull())
{
dc.drawPixmap( rect(), mBG);
}
}
// ============================================================================
// ============================================================================
{
//MMDebug("TransparentPanel::resizeEvent()\n")
updateBG();
//QWidget::resizeEvent(event);
}
// ============================================================================
void TransparentPanel
::moveEvent( QMoveEvent* event
) // ============================================================================
{
//MMDebug("TransparentPanel::moveEvent()\n")
updateBG();
//QWidget::moveEvent(event);
}
//// ============================================================================
//void TransparentPanel::enterEvent( QEvent* event )
//// ============================================================================
//{
// QWidget::enterEvent(event);
//}
//// ============================================================================
//void TransparentPanel::leaveEvent( QEvent* event )
//// ============================================================================
//{
// QWidget::leaveEvent(event);
//}
//// ============================================================================
//void TransparentPanel :: mousePressEvent ( QMouseEvent* event )
//// ============================================================================
//{
// QWidget::mousePressEvent( event );
//}
//// ============================================================================
//void TransparentPanel :: mouseReleaseEvent ( QMouseEvent* event )
//// ============================================================================
//{
// QWidget::mouseReleaseEvent( event );
//}
// ============================================================================
void TransparentPanel::updateBG()
// ============================================================================
{
// if (!isVisible())
// return;
//// setVisible(false);
// mBG = QPixmap(); // clear image for low memory situations on weak devices.
// QPoint screenTopLeft = mapToGlobal( geometry().topLeft() );
// int x = screenTopLeft.x();
// int y = screenTopLeft.y();
// int w = width();
// int h = height();
// //mBG = QPixmap::grabWindow(QApplication::desktop()->winId(), x,y, w,h );
// //QScreen* screen = QApplication::screens()->primaryScreen();
// QScreen* screen = QApplication::primaryScreen();
// if (screen)
// //mBG = screen->grabWindow(QApplication::desktop()->window()->winId(), x,y, w,h );
// mBG = screen->grabWindow((WId)GetDesktopWindow(), x,y, w,h );
//// setVisible(true);
// update();
QPoint p1
= mapToGlobal
( g.
topLeft() );
QPoint p2
= mapToGlobal
( g.
bottomRight() );
// setVisible(false);
QPoint screenTopLeft
= mapToGlobal
( pos
() );
int ax = screenTopLeft.x();
int ay = screenTopLeft.y();
int aw = width();
int ah = height();
// QImage img = pix.toImage();
// for ( int j = 0; j < img.height(); ++j )
// {
// for ( int i = 0; i < img.width(); ++i )
// {
// QColor c = img.pixel(i,j);
// c.setAlpha(255);
// img.setPixel( i,j, c.rgba() );
// }
// }
// //QImage img = pix.toImage();
// dc.drawImage( rect(), img );
// setUpdatesEnabled(false);
// hide();
//QPixmap pix = QDesktopWidget().grab( QRect(x,y,w,h) );
//QPixmap pix = QPixmap::grabWindow(QApplication::desktop()->winId(), x,y, w,h );
//QPixmap screenShot = QApplication::primaryScreen()->grabWindow( (WId)GetDesktopWindow() );
//mBG = screenShot.copy( ax,ay,aw,ah );
//mBG = screenShot.copy( r );
// mBG = QApplication::primaryScreen()->grabWindow( (WId)GetDesktopWindow(), r.left(), r.top(), r.width(), r.height() );
mBG = scr.copy( r );
#ifdef VERBOSE
std::stringstream s;
s << "pos ( x=" << pos().x() << ",y=" << pos().y() << ")\n";
s << "a ( x=" << ax << ",y=" << ay << ",w=" << aw << ",h=" << ah << ")\n";
s << "g ( x=" << g.left() << ",y=" << g.top() << ",w=" << g.width() << ",h=" << g.height() << ")\n";
s << "r ( x=" << r.left() << ",y=" << r.top() << ",w=" << r.width() << ",h=" << r.height() << ")\n";
s << "scr ( w=" << scr.width() << ",h=" << scr.height() << ")\n";
s << "mBG ( w=" << mBG.width() << ",h=" << mBG.height() << ")\n";
qDebug
() <<
QString::fromStdString(s.
str());
//MMPrint("%s", s.str().c_str())
#endif
// show();
// setUpdatesEnabled(true);
update();
}
#include "TransparentPanel.h"
#ifndef VERBOSE
#define VERBOSE 1
#endif
#include <QPainter>
#include <QMouseEvent>
#include <QApplication>
#include <QDesktopWidget>
#include <QScreen>
#include <QDebug>
// ============================================================================
TransparentPanel::TransparentPanel( QWidget* parent )
: QWidget(parent)
// ============================================================================
{
setMinimumSize(10,10);
setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
setAutoFillBackground( false );
//setAttribute( Qt::WA_OpaquePaintEvent );
setAttribute( Qt::WA_NoSystemBackground );
//setAttribute( Qt::WA_TranslucentBackground );
setUpdatesEnabled( true );
//MMDebug("TransparentPanel::TransparentPanel()\n")
//MMDebug("QApplication::desktop()->winId() = %x\n", (void*)QApplication::desktop()->winId() )
//MMDebug("GetDesktopWindow() = %x\n", (void*)GetDesktopWindow() )
updateBG();
}
// ============================================================================
TransparentPanel::~TransparentPanel()
// ============================================================================
{
//MMDebug("TransparentPanel::~TransparentPanel()\n")
}
// ============================================================================
void TransparentPanel::paintEvent( QPaintEvent* event )
// ============================================================================
{
if (!isVisible())
return;
//MMDebug("TransparentPanel::paintEvent()\n")
QPainter dc(this);
dc.setRenderHint( QPainter::NonCosmeticDefaultPen );
//dc.fillRect( rect(), Qt::white);
if (!mBG.isNull())
{
dc.drawPixmap( rect(), mBG);
}
QWidget::paintEvent(event);
}
// ============================================================================
void TransparentPanel :: resizeEvent(QResizeEvent* event)
// ============================================================================
{
//MMDebug("TransparentPanel::resizeEvent()\n")
updateBG();
//QWidget::resizeEvent(event);
}
// ============================================================================
void TransparentPanel::moveEvent( QMoveEvent* event)
// ============================================================================
{
//MMDebug("TransparentPanel::moveEvent()\n")
updateBG();
//QWidget::moveEvent(event);
}
//// ============================================================================
//void TransparentPanel::enterEvent( QEvent* event )
//// ============================================================================
//{
// QWidget::enterEvent(event);
//}
//// ============================================================================
//void TransparentPanel::leaveEvent( QEvent* event )
//// ============================================================================
//{
// QWidget::leaveEvent(event);
//}
//// ============================================================================
//void TransparentPanel :: mousePressEvent ( QMouseEvent* event )
//// ============================================================================
//{
// QWidget::mousePressEvent( event );
//}
//// ============================================================================
//void TransparentPanel :: mouseReleaseEvent ( QMouseEvent* event )
//// ============================================================================
//{
// QWidget::mouseReleaseEvent( event );
//}
// ============================================================================
void TransparentPanel::updateBG()
// ============================================================================
{
// if (!isVisible())
// return;
//// setVisible(false);
// mBG = QPixmap(); // clear image for low memory situations on weak devices.
// QPoint screenTopLeft = mapToGlobal( geometry().topLeft() );
// int x = screenTopLeft.x();
// int y = screenTopLeft.y();
// int w = width();
// int h = height();
// //mBG = QPixmap::grabWindow(QApplication::desktop()->winId(), x,y, w,h );
// //QScreen* screen = QApplication::screens()->primaryScreen();
// QScreen* screen = QApplication::primaryScreen();
// if (screen)
// //mBG = screen->grabWindow(QApplication::desktop()->window()->winId(), x,y, w,h );
// mBG = screen->grabWindow((WId)GetDesktopWindow(), x,y, w,h );
//// setVisible(true);
// update();
QRect g = geometry();
QPoint p1 = mapToGlobal( g.topLeft() );
QPoint p2 = mapToGlobal( g.bottomRight() );
// setVisible(false);
QPoint screenTopLeft = mapToGlobal( pos() );
int ax = screenTopLeft.x();
int ay = screenTopLeft.y();
int aw = width();
int ah = height();
QRect r( p1, p2 );
// QImage img = pix.toImage();
// for ( int j = 0; j < img.height(); ++j )
// {
// for ( int i = 0; i < img.width(); ++i )
// {
// QColor c = img.pixel(i,j);
// c.setAlpha(255);
// img.setPixel( i,j, c.rgba() );
// }
// }
// //QImage img = pix.toImage();
// dc.drawImage( rect(), img );
// setUpdatesEnabled(false);
// hide();
//QPixmap pix = QDesktopWidget().grab( QRect(x,y,w,h) );
//QPixmap pix = QPixmap::grabWindow(QApplication::desktop()->winId(), x,y, w,h );
//QPixmap screenShot = QApplication::primaryScreen()->grabWindow( (WId)GetDesktopWindow() );
//mBG = screenShot.copy( ax,ay,aw,ah );
//mBG = screenShot.copy( r );
// mBG = QApplication::primaryScreen()->grabWindow( (WId)GetDesktopWindow(), r.left(), r.top(), r.width(), r.height() );
QPixmap scr = QApplication::primaryScreen()->grabWindow( (WId)GetDesktopWindow() );
mBG = scr.copy( r );
#ifdef VERBOSE
std::stringstream s;
s << "pos ( x=" << pos().x() << ",y=" << pos().y() << ")\n";
s << "a ( x=" << ax << ",y=" << ay << ",w=" << aw << ",h=" << ah << ")\n";
s << "g ( x=" << g.left() << ",y=" << g.top() << ",w=" << g.width() << ",h=" << g.height() << ")\n";
s << "r ( x=" << r.left() << ",y=" << r.top() << ",w=" << r.width() << ",h=" << r.height() << ")\n";
s << "scr ( w=" << scr.width() << ",h=" << scr.height() << ")\n";
s << "mBG ( w=" << mBG.width() << ",h=" << mBG.height() << ")\n";
qDebug() << QString::fromStdString(s.str());
//MMPrint("%s", s.str().c_str())
#endif
// show();
// setUpdatesEnabled(true);
update();
}
To copy to clipboard, switch view to plain text mode
Bookmarks