Skip to content

Commit

Permalink
fix(#47): simplify titlebar
Browse files Browse the repository at this point in the history
  • Loading branch information
ffiirree committed Mar 18, 2024
1 parent c9c9223 commit f07c5d3
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 128 deletions.
11 changes: 6 additions & 5 deletions src/player/control-widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ ControlWidget::ControlWidget(FramelessWindow *parent)

// title bar
{
const auto title_bar = new TitleBar(parent);
title_bar->setObjectName("title-bar");
title_bar->setHideOnFullScreen(false);
layout->addWidget(title_bar);
title_bar_ = parent->titlebar();
title_bar_->setObjectName("title-bar");
title_bar_->setHideOnFullScreen(false);
layout->addWidget(title_bar_);
}

layout->addSpacerItem(new QSpacerItem(10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding));
Expand Down Expand Up @@ -133,7 +133,8 @@ ControlWidget::ControlWidget(FramelessWindow *parent)

bool ControlWidget::hideable() const
{
return !control_bar_->geometry().contains(mapFromGlobal(QCursor::pos())) &&
const auto pos = mapFromGlobal(QCursor::pos());
return !title_bar_->geometry().contains(pos) && !control_bar_->geometry().contains(pos) &&
!speed_box_->view()->isVisible();
}

Expand Down
3 changes: 3 additions & 0 deletions src/player/control-widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ enum class PlaybackMode
ANIMATED_IMAGE = 0x20,
};

class TitleBar;

class ControlWidget final : public QWidget
{
Q_OBJECT
Expand Down Expand Up @@ -45,6 +47,7 @@ public slots:
void validDruation(bool);

private:
TitleBar *title_bar_{};
QWidget *control_bar_{};
Slider *time_slider_{};
ComboBox *speed_box_{};
Expand Down
23 changes: 13 additions & 10 deletions src/resources/stylesheets/capturer.qss
Original file line number Diff line number Diff line change
Expand Up @@ -366,21 +366,24 @@ NavigationBar QCheckBox::indicator {
}

/*///////////////////////////////////////////////////////////////*/
TitleBar QCheckBox#icon-title {
font-size: 10pt;
}

TitleBar QCheckBox#icon-title::indicator {
TitleBar QPushButton#icon {
font-size: 8pt;
height: 1.5em;
width: 1.5em;

padding: 0.75em 1em;
width: 3em;

image: url(:/icons/capturer);
border: none;
padding: 0px;
border-radius: 0px;

background-color: transparent;

qproperty-iconSize: 26px;
}

TitleBar QLabel#title {
font-size: 10pt;
}

/* buttons */
TitleBar QCheckBox::indicator {
font-size: 8pt;
height: 1em;
Expand Down
18 changes: 8 additions & 10 deletions src/resources/stylesheets/player.qss
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@ ControlWidget TitleBar {
background-color: rgba(25, 25, 25, 175);
}

ControlWidget QCheckBox#icon-title {
ControlWidget TitleBar QPushButton#icon {
width: 0px;
}

ControlWidget TitleBar QLabel#title {
font-size: 10pt;
color: white;
padding-left: 0.75em;
min-width: 8em;
}

ControlWidget TitleBar QCheckBox#icon-title::indicator {
width: 0px;
height: 0px;
padding: 0px;
}

ControlWidget QCheckBox#pin-btn:hover,
ControlWidget QCheckBox#min-btn:hover,
ControlWidget QCheckBox#max-btn:hover,
ControlWidget QCheckBox#full-btn:hover {
background: rgba(0, 0, 0, 75);
background: rgba(0, 0, 0, 100);
}

ControlWidget TitleBar QCheckBox#pin-btn::indicator:unchecked {
Expand Down Expand Up @@ -75,7 +73,7 @@ QWidget#control-bar QCheckBox::indicator {
}

QWidget#control-bar QCheckBox::indicator:hover {
background-color: rgba(0, 0, 0, 75);
background-color: rgba(0, 0, 0, 100);
}

/* pause button */
Expand Down Expand Up @@ -129,7 +127,7 @@ QWidget#control-bar ComboBox#speed-box::down-arrow {

QWidget#control-bar ComboBox#speed-box:hover {
color: white;
background-color: rgba(0, 0, 0, 50);
background-color: rgba(0, 0, 0, 100);
}


Expand Down
33 changes: 14 additions & 19 deletions src/widgets/framelesswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "logging.h"
#include "platforms/window-effect.h"
#include "titlebar.h"

#include <QMouseEvent>
#include <QStyle>
Expand Down Expand Up @@ -57,15 +58,12 @@ bool FramelessWindow::isSizeFixed() const
return !minsize.isEmpty() && !maxsize.isEmpty() && (minsize == maxsize);
}

void FramelessWindow::maximize(const bool state) { state ? showMaximized() : showNormal(); }

void FramelessWindow::toggleMaximized() { !isMaximized() ? showMaximized() : showNormal(); }

void FramelessWindow::minimize(const bool state) { state ? showMinimized() : showNormal(); }

void FramelessWindow::fullscreen(const bool state) { state ? showFullScreen() : showNormal(); }
TitleBar *FramelessWindow::titlebar()
{
if (!titlebar_) titlebar_ = new TitleBar(this);

void FramelessWindow::toggleFullScreen() { isFullScreen() ? showNormal() : showFullScreen(); }
return titlebar_;
}

void FramelessWindow::toggleTransparentInput()
{
Expand Down Expand Up @@ -113,17 +111,6 @@ void FramelessWindow::hideEvent(QHideEvent *event)
QWidget::hideEvent(event);
}

void FramelessWindow::changeEvent(QEvent *event)
{
if (event->type() == QEvent::WindowStateChange) {
if (windowState() == Qt::WindowNoState) emit normalized();
if (windowState() & Qt::WindowMinimized) emit minimized();
if (windowState() & Qt::WindowMaximized) emit maximized();
if (windowState() & Qt::WindowFullScreen) emit fullscreened();
}
QWidget::changeEvent(event);
}

#ifdef Q_OS_LINUX
void FramelessWindow::updateCursor(const Qt::Edges edges)
{
Expand Down Expand Up @@ -301,6 +288,14 @@ bool FramelessWindow::nativeEvent(const QByteArray& eventType, void *message, Q_
}
}

if (res == HTCLIENT && titlebar_ && titlebar_->isVisible()) {
if (const auto pos = mapFromGlobal({ GET_X_LPARAM(wmsg->lParam), GET_Y_LPARAM(wmsg->lParam) });
titlebar_->geometry().contains(pos) && !titlebar_->isInSystemButtons(pos)) {
*result = HTCAPTION;
return true;
}
}

*result = static_cast<long>(res);
return true;
}
Expand Down
18 changes: 7 additions & 11 deletions src/widgets/framelesswindow.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef CAPTURER_FRAMELESS_WINDOW_H
#define CAPTURER_FRAMELESS_WINDOW_H

#include <QPointer>
#include <QWidget>

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
Expand All @@ -9,6 +10,8 @@
#define Q_NATIVE_EVENT_RESULT long
#endif

class TitleBar;

class FramelessWindow : public QWidget
{
Q_OBJECT
Expand All @@ -17,31 +20,24 @@ class FramelessWindow : public QWidget

[[nodiscard]] bool isSizeFixed() const;

TitleBar * titlebar();

public slots:
void maximize(bool = true);
void toggleMaximized();
void minimize(bool = true);
void fullscreen(bool = true);
void toggleFullScreen();
void toggleTransparentInput();

signals:
void hidden();
void closed();

void normalized();
void maximized();
void minimized();
void fullscreened();

protected:
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;

void closeEvent(QCloseEvent *) override;
void hideEvent(QHideEvent *event) override;
void changeEvent(QEvent *) override;

QPointer<TitleBar> titlebar_{};

bool transparent_input_{};

Expand Down
1 change: 1 addition & 0 deletions src/widgets/platforms/window-effect-windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#if _WIN32

#include <probe/library.h>
#include <probe/system.h>
#include <QWidget>
#include <Winuser.h>
Expand Down
1 change: 0 additions & 1 deletion src/widgets/platforms/window-effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#if _WIN32

#include <dwmapi.h>
#include <probe/library.h>

enum WINDOWCOMPOSITIONATTRIB : DWORD
{
Expand Down
Loading

0 comments on commit f07c5d3

Please sign in to comment.