这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/app.pro
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ PRECOMPILED_HEADER = src/app-pch.h
HEADERS += \
src/addtransparencytopaperdialog.h \
src/app-pch.h \
src/appearance.h \
src/buttonappearancewatcher.h \
src/importlayersdialog.h \
src/importpositiondialog.h \
src/layeropacitydialog.h \
Expand All @@ -92,6 +94,7 @@ HEADERS += \
src/timelinepage.h \
src/toolboxwidget.h \
src/toolspage.h \
src/titlebarwidget.h \
src/basedockwidget.h \
src/colorbox.h \
src/colorinspector.h \
Expand Down Expand Up @@ -128,6 +131,7 @@ HEADERS += \

SOURCES += \
src/addtransparencytopaperdialog.cpp \
src/buttonappearancewatcher.cpp \
src/importlayersdialog.cpp \
src/importpositiondialog.cpp \
src/layeropacitydialog.cpp \
Expand All @@ -145,6 +149,7 @@ SOURCES += \
src/timelinepage.cpp \
src/toolboxwidget.cpp \
src/toolspage.cpp \
src/titlebarwidget.cpp \
src/basedockwidget.cpp \
src/colorbox.cpp \
src/colorinspector.cpp \
Expand Down
6 changes: 6 additions & 0 deletions app/data/app.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@
<file>icons/blue.png</file>
<file>icons/green.png</file>
<file>icons/red.png</file>
<file>icons/themes/playful/window/window-float-button-active.svg</file>
<file>icons/themes/playful/window/window-close-button-active.svg</file>
<file>icons/themes/playful/window/window-close-button-normal-darkm.svg</file>
<file>icons/themes/playful/window/window-float-button-normal-darkm.svg</file>
<file>icons/themes/playful/window/window-float-button-normal.svg</file>
<file>icons/themes/playful/window/window-close-button-normal.svg</file>
</qresource>
<qresource prefix="/app">
<file>pencil2d_quick_guide.pdf</file>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions app/src/appearance.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*

Pencil2D - Traditional Animation Software
Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
Copyright (C) 2008-2009 Mj Mendoza IV
Copyright (C) 2012-2020 Matthew Chiawen Chang

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

*/
#ifndef APPEARANCE_H
#define APPEARANCE_H

#include <QIcon>

struct IconResource
{
QIcon lightMode;
QIcon darkMode;

const QIcon& iconForMode(bool darkmodeEnabled) const
{
if (darkmodeEnabled) {
return darkMode;
} else {
return lightMode;
}
}
};

#endif // APPEARANCE_H
45 changes: 45 additions & 0 deletions app/src/basedockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ GNU General Public License for more details.

#include "basedockwidget.h"
#include "platformhandler.h"
#include "titlebarwidget.h"

BaseDockWidget::BaseDockWidget(QWidget* pParent)
: QDockWidget(pParent, Qt::Tool)
Expand All @@ -34,8 +35,52 @@ BaseDockWidget::BaseDockWidget(QWidget* pParent)
"border-width: 1px; }");
}
#endif

mTitleBarWidget = new TitleBarWidget(pParent);
mNoTitleBarWidget = new QWidget(pParent);

setTitleBarWidget(mTitleBarWidget);

connect(mTitleBarWidget, &TitleBarWidget::closeButtonPressed, this, &BaseDockWidget::close);

connect(mTitleBarWidget, &TitleBarWidget::undockButtonPressed, this, [this] {
setFloating(!isFloating());
});

connect(this, &QDockWidget::topLevelChanged, mTitleBarWidget, &TitleBarWidget::setIsFloating);
connect(this, &QDockWidget::windowTitleChanged, mTitleBarWidget, &TitleBarWidget::setTitle);
}

BaseDockWidget::~BaseDockWidget()
{
}

void BaseDockWidget::lock(bool locked)
{
// https://doc.qt.io/qt-5/qdockwidget.html#setTitleBarWidget
// A empty QWidget results in the title bar being hidden.
// nullptr means removing the custom title bar and restoring the default one

if (locked) {
setTitleBarWidget(mNoTitleBarWidget);
} else {
setTitleBarWidget(mTitleBarWidget);
}

mLocked = locked;
}

void BaseDockWidget::setTitle(const QString& title)
{
if (!mTitleBarWidget) { return; }
mTitleBarWidget->setTitle(title);
}

void BaseDockWidget::resizeEvent(QResizeEvent *event)
{
QDockWidget::resizeEvent(event);

if (mTitleBarWidget) {
mTitleBarWidget->resizeEvent(event);
}
}
15 changes: 14 additions & 1 deletion app/src/basedockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ GNU General Public License for more details.
#include <QDockWidget>

class Editor;

class TitleBarWidget;

class BaseDockWidget : public QDockWidget
{
Expand All @@ -34,11 +34,24 @@ class BaseDockWidget : public QDockWidget
virtual void initUI() = 0;
virtual void updateUI() = 0;

void lock(bool locked);
void setTitle(const QString& title);

bool isLocked() const { return mLocked; }

Editor* editor() const { return mEditor; }
void setEditor( Editor* e ) { mEditor = e; }

protected:
void resizeEvent(QResizeEvent* event) override;

private:
Editor* mEditor = nullptr;

QWidget* mNoTitleBarWidget = nullptr;
TitleBarWidget* mTitleBarWidget = nullptr;

bool mLocked = false;
};

#endif // BASEDOCKWIDGET_H
85 changes: 85 additions & 0 deletions app/src/buttonappearancewatcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*

Pencil2D - Traditional Animation Software
Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
Copyright (C) 2012-2020 Matthew Chiawen Chang

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

*/
#include "buttonappearancewatcher.h"

#include <QAbstractButton>
#include <QEvent>

#include "platformhandler.h"

ButtonAppearanceWatcher::ButtonAppearanceWatcher(IconResource normalIconResource,
IconResource hoverIconResource,
QObject* parent) :
QObject(parent),
mNormalIconResource(normalIconResource),
mHoverIconResource(hoverIconResource)
{}

bool ButtonAppearanceWatcher::eventFilter(QObject* watched, QEvent* event)
{
QAbstractButton* button = qobject_cast<QAbstractButton*>(watched);
if (!button) {
return false;
}

IconResource res = mNormalIconResource;
AppearanceEventType apType = determineAppearanceEvent(event);

if (shouldUpdateResource(event, apType)) {
if (event->type() == QEvent::ApplicationPaletteChange) {
res = mNormalIconResource;
}
else if (event->type() == QEvent::Enter) {
res = mHoverIconResource;
}
else if (event->type() == QEvent::Leave) {
res = mNormalIconResource;
}
mOldAppearanceType = apType;

bool isDarkmode = PlatformHandler::isDarkMode();
button->setIcon(res.iconForMode(isDarkmode));
return true;
}

return false;
}

AppearanceEventType ButtonAppearanceWatcher::determineAppearanceEvent(QEvent *event) const
{
if (event->type() == QEvent::ApplicationPaletteChange) {
bool isDarkmode = PlatformHandler::isDarkMode();
if (isDarkmode) {
return AppearanceEventType::DARK_APPEARANCE;
} else {
return AppearanceEventType::LIGHT_APPEARANCE;
}
} else if (event->type() == QEvent::Enter) {
return AppearanceEventType::ICON_ACTIVE;
} else if (event->type() == QEvent::Leave) {
return AppearanceEventType::ICON_NORMAL;
}

return AppearanceEventType::NONE;
}

bool ButtonAppearanceWatcher::shouldUpdateResource(QEvent* event, AppearanceEventType appearanceType) const
{
if (appearanceType == mOldAppearanceType) { return false; }

return determineAppearanceEvent(event) != AppearanceEventType::NONE;
}
51 changes: 51 additions & 0 deletions app/src/buttonappearancewatcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*

Pencil2D - Traditional Animation Software
Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
Copyright (C) 2012-2020 Matthew Chiawen Chang

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

*/
#ifndef BUTTONAPPEARANCEWATCHER_H
#define BUTTONAPPEARANCEWATCHER_H

enum class AppearanceEventType
{
NONE,
LIGHT_APPEARANCE,
DARK_APPEARANCE,
ICON_NORMAL,
ICON_ACTIVE
};

#include "appearance.h"

class ButtonAppearanceWatcher : public QObject
{
Q_OBJECT

public:
explicit ButtonAppearanceWatcher(IconResource normalIconResource,
IconResource hoverIconResource,
QObject * parent = nullptr);
virtual bool eventFilter(QObject * watched, QEvent * event) override;

private:
bool shouldUpdateResource(QEvent* event, AppearanceEventType appearanceType) const;
AppearanceEventType determineAppearanceEvent(QEvent* event) const;

const IconResource mNormalIconResource;
const IconResource mHoverIconResource;

AppearanceEventType mOldAppearanceType = AppearanceEventType::NONE;
};

#endif // BUTTONAPPEARANCEWATCHER_H
9 changes: 2 additions & 7 deletions app/src/mainwindow2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1030,15 +1030,10 @@ void MainWindow2::lockWidgets(bool shouldLock)
QDockWidget::DockWidgetFeature::DockWidgetMovable |
QDockWidget::DockWidgetFeature::DockWidgetFloatable);

for (QDockWidget* d : mDockWidgets)
for (BaseDockWidget* d : mDockWidgets)
{
d->setFeatures(feat);

// https://doc.qt.io/qt-5/qdockwidget.html#setTitleBarWidget
// A empty QWidget looks like the tittle bar is hidden.
// nullptr means removing the custom title bar and restoring the default one
QWidget* customTitleBarWidget = shouldLock ? (new QWidget) : nullptr;
d->setTitleBarWidget(customTitleBarWidget);
d->lock(shouldLock);
}
}

Expand Down
Loading
Loading