Compare commits
1 Commits
work/gfgit
...
work/gfgit
Author | SHA1 | Date |
---|---|---|
gfgit | 3832b4efec |
|
@ -23,6 +23,9 @@ set(files
|
|||
src/app-itemdelegate.h
|
||||
src/settings.h
|
||||
src/main.cpp
|
||||
|
||||
src/window.h
|
||||
src/window.cpp
|
||||
)
|
||||
|
||||
include(LXQtTranslate)
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
// Should be after Qt headers
|
||||
#include "src/app-switcher.h"
|
||||
|
||||
#include "src/window.h"
|
||||
|
||||
LXQt::LXQtTheme currentTheme()
|
||||
{
|
||||
QString themeName = Settings::instance().theme();
|
||||
|
@ -58,5 +60,8 @@ int main(int argc, char* argv[])
|
|||
QWidget hiddenPreviewParent(0, Qt::Tool);
|
||||
AppSwitcher switcher(&hiddenPreviewParent);
|
||||
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
#include "window.h"
|
||||
|
||||
#include <QGestureEvent>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QWidget{parent}
|
||||
{
|
||||
setAttribute(Qt::WA_AcceptTouchEvents);
|
||||
|
||||
grabGesture(Qt::PanGesture);
|
||||
grabGesture(Qt::SwipeGesture);
|
||||
grabGesture(Qt::PinchGesture);
|
||||
}
|
||||
|
||||
bool MainWindow::event(QEvent *e)
|
||||
{
|
||||
if(e->type() == QEvent::TouchBegin)
|
||||
{
|
||||
qt_noop();
|
||||
}
|
||||
|
||||
if(e->type() == QEvent::Gesture)
|
||||
{
|
||||
QGestureEvent *ev = static_cast<QGestureEvent *>(e);
|
||||
|
||||
if(m_activeGesture != Qt::NoGesture)
|
||||
{
|
||||
for(QGesture *gesture : ev->activeGestures())
|
||||
{
|
||||
if(gesture->gestureType() != m_activeGesture)
|
||||
ev->ignore(gesture);
|
||||
}
|
||||
|
||||
QGesture *gesture = ev->gesture(m_activeGesture);
|
||||
if(!gesture || gesture->state() != Qt::GestureUpdated)
|
||||
{
|
||||
//Reset
|
||||
setActiveGesture(Qt::LastGestureType);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (QGesture *swipe = ev->gesture(Qt::SwipeGesture))
|
||||
{
|
||||
setActiveGesture(Qt::SwipeGesture);
|
||||
ev->accept(swipe);
|
||||
}
|
||||
else if (QGesture *pan = ev->gesture(Qt::PanGesture))
|
||||
{
|
||||
setActiveGesture(Qt::PanGesture);
|
||||
ev->accept(pan);
|
||||
}
|
||||
else if (QGesture *pinch = ev->gesture(Qt::PinchGesture))
|
||||
{
|
||||
setActiveGesture(Qt::PinchGesture);
|
||||
ev->accept(pinch);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return QWidget::event(e);
|
||||
}
|
||||
|
||||
Qt::GestureType MainWindow::activeGesture() const
|
||||
{
|
||||
return m_activeGesture;
|
||||
}
|
||||
|
||||
void MainWindow::setActiveGesture(Qt::GestureType newActiveGesture)
|
||||
{
|
||||
m_activeGesture = newActiveGesture;
|
||||
|
||||
QColor col;
|
||||
switch (m_activeGesture)
|
||||
{
|
||||
case Qt::LastGestureType:
|
||||
col = Qt::gray;
|
||||
break;
|
||||
case Qt::SwipeGesture:
|
||||
col = Qt::green;
|
||||
break;
|
||||
case Qt::PanGesture:
|
||||
col = Qt::red;
|
||||
break;
|
||||
case Qt::PinchGesture:
|
||||
col = Qt::blue;
|
||||
break;
|
||||
default:
|
||||
col = Qt::black;
|
||||
break;
|
||||
}
|
||||
|
||||
QPalette p = palette();
|
||||
p.setColor(QPalette::Window, col);
|
||||
setPalette(p);
|
||||
update();
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class MainWindow : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
|
||||
Qt::GestureType activeGesture() const;
|
||||
void setActiveGesture(Qt::GestureType newActiveGesture);
|
||||
|
||||
protected:
|
||||
bool event(QEvent *e) override;
|
||||
|
||||
private:
|
||||
Qt::GestureType m_activeGesture = Qt::LastGestureType;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
Loading…
Reference in New Issue