Commit 97caab42 authored by WINTZ Julien's avatar WINTZ Julien

Towards passthrough widget.

parent eeb67417
......@@ -18,6 +18,7 @@ add_subdirectory(dtkWidgetsLayout)
add_subdirectory(dtkWidgetsMenu)
add_subdirectory(dtkWidgetsOverlayPaneItems)
add_subdirectory(dtkWidgetsParameter)
add_subdirectory(dtkWidgetsPassThrough)
add_subdirectory(dtkWidgetsScroller)
add_subdirectory(dtkWidgetsWorkspace)
......
## Version: $Id$
##
######################################################################
##
### Commentary:
##
######################################################################
##
### Change Log:
##
######################################################################
##
### Code:
project(dtkWidgetsPassTrough)
## #################################################################
## Sources
## #################################################################
set(${PROJECT_NAME}_SOURCES main.cpp)
## #################################################################
## Build rules
## #################################################################
qt5_add_resources(${PROJECT_NAME}_SOURCES_RCC ${${PROJECT_NAME}_SOURCES_QRC})
add_executable(${PROJECT_NAME} MACOSX_BUNDLE
${${PROJECT_NAME}_SOURCES})
target_link_libraries(${PROJECT_NAME} Qt5::Core)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} dtkThemes)
target_link_libraries(${PROJECT_NAME} dtkThemesWidgets)
target_link_libraries(${PROJECT_NAME} dtkWidgets)
## ###################################################################
## Bundle setup
## ###################################################################
if(APPLE)
set(${PROJECT_NAME}_RESOURCE_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.app/Contents/Resources)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E make_directory ${${PROJECT_NAME}_RESOURCE_DIR})
endif(APPLE)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.plist.in ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.plist)
if(APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.plist)
endif(APPLE)
######################################################################
### CMakeLists.txt ends here
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>@PROJECT_NAME@</string>
<key>CFBundleGetInfoString</key>
<string></string>
<key>CFBundleIconFile</key>
<string>@PROJECT_NAME@</string>
<key>CFBundleIdentifier</key>
<string>fr.inria.dtkWidgetsMenu</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLongVersionString</key>
<string>@dtkWidgets_VERSION@</string>
<key>CFBundleName</key>
<string>@PROJECT_NAME@</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>@dtkWidgets_VERSION@</string>
<key>CFBundleVersion</key>
<string>@dtkWidgets_VERSION@</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>Inria</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include <QtCore>
#include <QtWidgets>
#include <dtkWidgets>
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsPassThrough : public QFrame
{
Q_OBJECT
public:
dtkWidgetsPassThrough(QWidget *parent = nullptr);
public:
QSize sizeHint(void) const override
{
return QSize(200, 200);
}
protected slots:
void grab(void);
protected:
void paintEvent(QPaintEvent *) override;
protected:
void mousePressEvent(QMouseEvent *event) override
{
this->ignre = true;
this->o_pos = event->globalPos();
}
void mouseMoveEvent(QMouseEvent *event) override
{
this->c_pos = event->globalPos();
this->d_pos = this->c_pos - this->o_pos;
this->topLevelWidget()->move(this->topLevelWidget()->pos() + this->d_pos);
this->o_pos = this->c_pos;
}
void mouseReleaseEvent(QMouseEvent *) override
{
this->ignre = false;
this->grab();
}
private:
QPixmap buffer;
public:
QPoint o_pos;
QPoint c_pos;
QPoint d_pos;
public:
bool ignre = false;
bool dirty = false;
};
dtkWidgetsPassThrough::dtkWidgetsPassThrough(QWidget *parent) : QFrame(parent)
{
this->setAttribute(Qt::WA_NoSystemBackground);
this->setAttribute(Qt::WA_TranslucentBackground);
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
this->setWindowFlags(Qt::FramelessWindowHint);
}
void dtkWidgetsPassThrough::grab(void)
{
this->dirty = true;
this->repaint();
qApp->processEvents();
QScreen *screen = qApp->primaryScreen();
if (const QWindow *window = windowHandle())
screen = window->screen();
if (!screen)
return;
QPoint origin = this->mapToGlobal(QPoint(0, 0));
qreal s = screen->devicePixelRatio();
qreal d = 0; // -50;
this->buffer = screen->grabWindow(0).copy(d+s*origin.x(), d+s*origin.y(), s*this->width(), s*this->height());
this->dirty = false;
this->repaint();
}
void dtkWidgetsPassThrough::paintEvent(QPaintEvent *event)
{
if (this->ignre)
return;
QPainter painter(this);
if(!this->dirty) {
painter.drawPixmap(event->rect(), buffer);
painter.fillRect(event->rect(), QColor(64, 0, 64, 64));
painter.setPen(QPen(Qt::yellow, 50));
painter.drawLine(event->rect().topLeft(), event->rect().topRight());
painter.drawLine(event->rect().topRight(), event->rect().bottomRight());
painter.drawLine(event->rect().bottomRight(), event->rect().bottomLeft());
painter.drawLine(event->rect().bottomLeft(), event->rect().topLeft());
} else {
painter.fillRect(event->rect(), QColor(0, 0, 0, 0));
}
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dummy : public dtkWidgetsMainWindow
{
public:
dummy(QWidget *parent = nullptr);
~dummy(void);
protected:
void paintEvent(QPaintEvent *) override;
};
dummy::dummy(QWidget *parent) : dtkWidgetsMainWindow(parent)
{
QFrame *central = new QFrame(this);
// this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// this->setAttribute(Qt::WA_NoSystemBackground, true);
// this->setAttribute(Qt::WA_TranslucentBackground, true);
// this->setWindowFlags(Qt::FramelessWindowHint);
this->menubar();
this->populate();
this->setCentralWidget(central);
this->menubar()->touch();
}
dummy::~dummy(void)
{
}
void dummy::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.fillRect(event->rect(), QColor(0, 0, 0, 128));
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
dtkApplication *application = dtkApplication::create(argc, argv);
application->initialize();
dtkThemesEngine::instance()->apply("Spacegrey");
dummy *window = new dummy;
window->resize(800, 400);
window->show();
window->raise();
dtkWidgetsPassThrough *widget = new dtkWidgetsPassThrough;
widget->resize(800, 400);
widget->show();
widget->raise();
dtkThemesEngine::instance()->apply("Spacegrey");
int status = application->exec();
delete application;
}
// ///////////////////////////////////////////////////////////////////
#include "main.moc"
//
// main.cpp ends here
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment