修复无DXCB且WM不支持拖动情况下窗口的拖拽

This commit is contained in:
RigoLigo
2021-07-07 18:23:38 +08:00
parent 0729cfffb7
commit 0885b7ca13
5 changed files with 73 additions and 32 deletions

View File

@@ -162,6 +162,8 @@ SpkUi::SpkMainWidget::SpkMainWidget(QWidget *parent) : QFrame(parent)
HorizontalDivide->setSpacing(0); HorizontalDivide->setSpacing(0);
HorizontalDivide->setContentsMargins(0, 0, 0, 0); HorizontalDivide->setContentsMargins(0, 0, 0, 0);
HorizontalDivide->setAlignment(Qt::AlignLeft); HorizontalDivide->setAlignment(Qt::AlignLeft);
if(!SpkUi::States::IsUsingDtkPlugin)
HorizontalDivide->addSpacing(SpkWindow::BorderWidth);
HorizontalDivide->addWidget(SideBarRestrictor); HorizontalDivide->addWidget(SideBarRestrictor);
HorizontalDivide->addLayout(VLayMain); HorizontalDivide->addLayout(VLayMain);

View File

@@ -28,6 +28,12 @@ namespace SpkUi
QSize PrimaryScreenSize; QSize PrimaryScreenSize;
SpkDtkPlugin *DtkPlugin = nullptr; SpkDtkPlugin *DtkPlugin = nullptr;
QStyle *OldSystemStyle = nullptr; QStyle *OldSystemStyle = nullptr;
QList<QColor> CurrentColorSet;
namespace States
{
bool IsDDE = false, IsUsingDtkPlugin = false;
}
namespace Priv namespace Priv
{ {
@@ -51,7 +57,7 @@ namespace SpkUi
signal(SIGFPE, SpkUi::CrashSignalHandler); signal(SIGFPE, SpkUi::CrashSignalHandler);
// Prepare theme following for DDE // Prepare theme following for DDE
if(CheckIsDeepinDesktop()) if((States::IsDDE = CheckIsDeepinDesktop()))
PrepareForDeepinDesktop(); PrepareForDeepinDesktop();
// Misc data initialization // Misc data initialization
@@ -83,12 +89,18 @@ namespace SpkUi
qApp->addLibraryPath("/usr/local/lib"); qApp->addLibraryPath("/usr/local/lib");
qApp->addLibraryPath("/usr/lib"); qApp->addLibraryPath("/usr/lib");
#endif #endif
if(!qgetenv("SPARK_NO_DTK_PLUGIN").toInt())
{
QPluginLoader p("libspkdtkplugin"); QPluginLoader p("libspkdtkplugin");
if(p.load()) if(p.load())
{ {
auto i = qobject_cast<SpkDtkPlugin*>(p.instance()); auto i = qobject_cast<SpkDtkPlugin*>(p.instance());
if(i) if(i)
{
DtkPlugin = i; DtkPlugin = i;
States::IsUsingDtkPlugin = true;
}
}
} }
// FIXME: Chameleon style kept adding unwanted blue focus indication border // FIXME: Chameleon style kept adding unwanted blue focus indication border
@@ -117,26 +129,28 @@ namespace SpkUi
switch(aStyle) switch(aStyle)
{ {
case Light: case Light:
CurrentStylesheet = StylesheetFromColors( static auto LightColor = QList<QColor>{
QList<QColor>{
0x353535, 0x353535, 0xff0000, 0x0070ff, 0x2987ff, 0x353535, 0x353535, 0xff0000, 0x0070ff, 0x2987ff,
0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838, 0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838,
ColorTextOnBackground(0x0070ff) ColorTextOnBackground(0x0070ff)
}); };
CurrentStylesheet = StylesheetFromColors(LightColor);
qApp->setStyleSheet(CurrentStylesheet); qApp->setStyleSheet(CurrentStylesheet);
// TODO // TODO
ColorLine = Qt::black; ColorLine = Qt::black;
break; break;
case Dark: case Dark:
CurrentStylesheet = StylesheetFromColors( static auto DarkColor = QList<QColor>{
QList<QColor>{
0x353535, 0x353535, 0xff0000, 0x0070ff, 0x2987ff, 0x353535, 0x353535, 0xff0000, 0x0070ff, 0x2987ff,
0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838, 0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838,
ColorTextOnBackground(0x0070ff) ColorTextOnBackground(0x0070ff)
}); };
CurrentStylesheet = StylesheetFromColors(DarkColor);
CurrentColorSet = DarkColor;
qApp->setStyleSheet(CurrentStylesheet); qApp->setStyleSheet(CurrentStylesheet);
ColorLine = Qt::white; ColorLine = Qt::white;
break; break;
// IDE complains about default label covering all conditions, commented
// default: // default:
// sWarn(QObject::tr("SetGlobalStyle invoked with unknown style %1.") // sWarn(QObject::tr("SetGlobalStyle invoked with unknown style %1.")
// .arg(static_cast<int>(aStyle))); // .arg(static_cast<int>(aStyle)));

View File

@@ -21,7 +21,7 @@ SpkWindow::SpkWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(paren
mCornerRadius = 5; mCornerRadius = 5;
mUserCentralWidget = nullptr; mUserCentralWidget = nullptr;
mResizable = true; mResizable = true;
mResizing = false; mMoving = mResizing = false;
mCloseHook = nullptr; mCloseHook = nullptr;
mMaximized = windowState().testFlag(Qt::WindowMaximized); mMaximized = windowState().testFlag(Qt::WindowMaximized);
mUseCustomEvents = SpkUi::DtkPlugin == nullptr; mUseCustomEvents = SpkUi::DtkPlugin == nullptr;
@@ -63,6 +63,17 @@ bool SpkWindow::event(QEvent *evt)
mEdgesBeingResized = edge; mEdgesBeingResized = edge;
return true; return true;
} }
else
{
if(!QMainWindow::event(evt) || 1)
{
mMoveOffset = e->globalPos() - pos();
setCursor(Qt::SizeAllCursor);
mMoving = true;
mResizing = false;
}
return true;
}
break; break;
} }
case QEvent::MouseButtonRelease: case QEvent::MouseButtonRelease:
@@ -71,30 +82,39 @@ bool SpkWindow::event(QEvent *evt)
auto e = static_cast<QMouseEvent*>(evt); auto e = static_cast<QMouseEvent*>(evt);
if(e->button() != Qt::LeftButton) break; if(e->button() != Qt::LeftButton) break;
mResizing = false; mResizing = false;
mMoving = false;
unsetCursor();
return true; return true;
break; break;
} }
case QEvent::HoverMove: case QEvent::HoverMove:
{ {
if(mResizing || !mResizable) break; if((mResizing || !mResizable) && !mMoving) break;
if(mMaximized) if(mMaximized)
{ {
unsetCursor(); unsetCursor();
break; break;
} }
if(mResizable && !mMoving)
{
auto e = static_cast<QHoverEvent*>(evt); auto e = static_cast<QHoverEvent*>(evt);
auto edge = DetectEdgeOnThis(e->pos()); auto edge = DetectEdgeOnThis(e->pos());
SetMouseCursor(edge); SetMouseCursor(edge);
}
break; break;
} }
case QEvent::MouseMove: case QEvent::MouseMove:
{ {
if(!mResizable) break; if(mMaximized) break;
auto e = static_cast<QMouseEvent*>(evt); auto e = static_cast<QMouseEvent*>(evt);
if(mResizing && !mMaximized) if(mResizing && mResizable)
{ {
ResizeWindowByCursor(e->globalPos()); ResizeWindowByCursor(e->globalPos());
return true; return true; // Intercept resize movements
}
else if(mMoving)
{
move(e->globalPos() - mMoveOffset);
} }
break; break;
} }
@@ -221,8 +241,6 @@ void SpkWindow::SetWindowTheme(SpkWindow::SpkWindowStyle style)
case Dark: case Dark:
SpkUi::SetGlobalStyle(SpkUi::SpkUiStyle::Dark); SpkUi::SetGlobalStyle(SpkUi::SpkUiStyle::Dark);
break; break;
default:
;
} }
} }

View File

@@ -25,6 +25,12 @@ namespace SpkUi
extern QSize PrimaryScreenSize; extern QSize PrimaryScreenSize;
extern SpkDtkPlugin *DtkPlugin; extern SpkDtkPlugin *DtkPlugin;
extern QStyle *OldSystemStyle; extern QStyle *OldSystemStyle;
extern QList<QColor> CurrentColorSet;
namespace States
{
extern bool IsDDE, IsUsingDtkPlugin;
}
namespace Priv namespace Priv
{ {

View File

@@ -18,6 +18,7 @@ class SpkWindow : public QMainWindow
Q_OBJECT Q_OBJECT
public: public:
enum SpkWindowStyle { Dark, Light }; enum SpkWindowStyle { Dark, Light };
static constexpr int BorderWidth = 7;
private: private:
QWidget *mCentralWidget, *mUserCentralWidget; QWidget *mCentralWidget, *mUserCentralWidget;
@@ -26,24 +27,23 @@ class SpkWindow : public QMainWindow
int mCornerRadius; int mCornerRadius;
bool mMoving, mResizing, mMaximized, mResizable; bool mMoving, mResizing, mMaximized, mResizable;
Qt::Edges mEdgesBeingResized; Qt::Edges mEdgesBeingResized;
QPoint mMoveOffset;
bool (*mCloseHook)(void); bool (*mCloseHook)(void);
bool mUseCustomEvents; bool mUseCustomEvents;
static constexpr int BorderWidth = 10;
public: public:
SpkWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); SpkWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
~SpkWindow() override; ~SpkWindow() override;
void SetCentralWidget(QWidget *); void SetCentralWidget(QWidget *);
bool GetUseTitleBar(); bool GetUseTitleBar();
bool GetResizable() { return mResizable; }; bool GetResizable() { return mResizable; }
void SetCloseHook(bool(*f)(void)); void SetCloseHook(bool(*f)(void));
public slots: public slots:
void SetCornerRadius(int); void SetCornerRadius(int);
void SetWindowTheme(SpkWindowStyle); void SetWindowTheme(SpkWindowStyle);
void SetUseTitleBar(bool); void SetUseTitleBar(bool);
void SetResizable(bool a) { mResizable = a; }; void SetResizable(bool a) { mResizable = a; }
void SetCentralMargin(int, int, int, int); void SetCentralMargin(int, int, int, int);
void ClearCloseHook(); void ClearCloseHook();
void RecalculateSize(); void RecalculateSize();
@@ -59,6 +59,7 @@ class SpkWindow : public QMainWindow
void SetMouseCursor(Qt::Edges); void SetMouseCursor(Qt::Edges);
void ResizeWindowByCursor(QPoint); void ResizeWindowByCursor(QPoint);
void closeEvent(QCloseEvent *) override; void closeEvent(QCloseEvent *) override;
// void paintEvent(QPaintEvent *) override;
private: private:
void PopulateUi(); void PopulateUi();