forked from zzag/material-decoration
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 28d0616
Showing
16 changed files
with
1,092 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
--- | ||
Language: Cpp | ||
# BasedOnStyle: WebKit | ||
AccessModifierOffset: -4 | ||
AlignAfterOpenBracket: DontAlign | ||
AlignConsecutiveAssignments: false | ||
AlignConsecutiveDeclarations: false | ||
AlignEscapedNewlines: Right | ||
AlignOperands: false | ||
AlignTrailingComments: true | ||
AllowAllParametersOfDeclarationOnNextLine: true | ||
AllowShortBlocksOnASingleLine: false | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: All | ||
AllowShortIfStatementsOnASingleLine: false | ||
AllowShortLoopsOnASingleLine: false | ||
AlwaysBreakAfterDefinitionReturnType: None | ||
AlwaysBreakAfterReturnType: None | ||
AlwaysBreakBeforeMultilineStrings: false | ||
AlwaysBreakTemplateDeclarations: false | ||
BinPackArguments: true | ||
BinPackParameters: true | ||
BraceWrapping: | ||
AfterClass: false | ||
AfterControlStatement: false | ||
AfterEnum: false | ||
AfterFunction: true | ||
AfterNamespace: false | ||
AfterObjCDeclaration: false | ||
AfterStruct: false | ||
AfterUnion: false | ||
AfterExternBlock: false | ||
BeforeCatch: false | ||
BeforeElse: false | ||
IndentBraces: false | ||
SplitEmptyFunction: true | ||
SplitEmptyRecord: true | ||
SplitEmptyNamespace: true | ||
BreakBeforeBinaryOperators: All | ||
BreakBeforeBraces: WebKit | ||
BreakBeforeInheritanceComma: false | ||
BreakBeforeTernaryOperators: true | ||
BreakConstructorInitializersBeforeComma: false | ||
BreakConstructorInitializers: BeforeComma | ||
BreakAfterJavaFieldAnnotations: false | ||
BreakStringLiterals: true | ||
ColumnLimit: 0 | ||
CommentPragmas: '^ IWYU pragma:' | ||
CompactNamespaces: false | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: false | ||
ConstructorInitializerIndentWidth: 4 | ||
ContinuationIndentWidth: 4 | ||
Cpp11BracedListStyle: false | ||
DerivePointerAlignment: false | ||
DisableFormat: false | ||
ExperimentalAutoDetectBinPacking: false | ||
FixNamespaceComments: false | ||
ForEachMacros: | ||
- foreach | ||
- Q_FOREACH | ||
- BOOST_FOREACH | ||
IncludeBlocks: Preserve | ||
IncludeCategories: | ||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/' | ||
Priority: 2 | ||
- Regex: '^(<|"(gtest|gmock|isl|json)/)' | ||
Priority: 3 | ||
- Regex: '.*' | ||
Priority: 1 | ||
IncludeIsMainRegex: '(Test)?$' | ||
IndentCaseLabels: false | ||
IndentPPDirectives: None | ||
IndentWidth: 4 | ||
IndentWrappedFunctionNames: false | ||
JavaScriptQuotes: Leave | ||
JavaScriptWrapImports: true | ||
KeepEmptyLinesAtTheStartOfBlocks: false | ||
MacroBlockBegin: '' | ||
MacroBlockEnd: '' | ||
MaxEmptyLinesToKeep: 1 | ||
NamespaceIndentation: Inner | ||
ObjCBlockIndentWidth: 4 | ||
ObjCSpaceAfterProperty: true | ||
ObjCSpaceBeforeProtocolList: true | ||
PenaltyBreakAssignment: 2 | ||
PenaltyBreakBeforeFirstCallParameter: 19 | ||
PenaltyBreakComment: 300 | ||
PenaltyBreakFirstLessLess: 120 | ||
PenaltyBreakString: 1000 | ||
PenaltyExcessCharacter: 1000000 | ||
PenaltyReturnTypeOnItsOwnLine: 60 | ||
PointerAlignment: Left | ||
RawStringFormats: | ||
- Delimiter: pb | ||
Language: TextProto | ||
BasedOnStyle: google | ||
ReflowComments: true | ||
SortIncludes: true | ||
SortUsingDeclarations: true | ||
SpaceAfterCStyleCast: false | ||
SpaceAfterTemplateKeyword: true | ||
SpaceBeforeAssignmentOperators: true | ||
SpaceBeforeParens: ControlStatements | ||
SpaceInEmptyParentheses: false | ||
SpacesBeforeTrailingComments: 1 | ||
SpacesInAngles: false | ||
SpacesInContainerLiterals: true | ||
SpacesInCStyleCastParentheses: false | ||
SpacesInParentheses: false | ||
SpacesInSquareBrackets: false | ||
Standard: Cpp11 | ||
TabWidth: 8 | ||
UseTab: Never | ||
... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"files.associations": { | ||
"array": "cpp", | ||
"string_view": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
cmake_minimum_required (VERSION 3.0) | ||
project (material-decoration) | ||
|
||
add_definitions (-Wall -Werror) | ||
|
||
include (FeatureSummary) | ||
find_package (ECM 0.0.9 REQUIRED NO_MODULE) | ||
|
||
set (CMAKE_MODULE_PATH | ||
${CMAKE_MODULE_PATH} | ||
${ECM_MODULE_PATH} | ||
${ECM_KDE_MODULE_DIR} | ||
"${CMAKE_SOURCE_DIR}/cmake" | ||
"${CMAKE_SOURCE_DIR}/cmake/Modules" | ||
) | ||
|
||
include (ECMInstallIcons) | ||
include (KDEInstallDirs) | ||
include (KDECMakeSettings) | ||
include (KDECompilerSettings NO_POLICY_SCOPE) | ||
|
||
add_subdirectory (src) | ||
|
||
feature_summary(WHAT ALL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
find_package (KDecoration2 REQUIRED) | ||
|
||
find_package (Qt5 REQUIRED COMPONENTS | ||
Core | ||
Gui | ||
) | ||
|
||
find_package (KF5 REQUIRED COMPONENTS | ||
Config | ||
CoreAddons | ||
GuiAddons | ||
WindowSystem | ||
) | ||
|
||
set (decoration_SRCS | ||
CloseButton.cc | ||
Decoration.cc | ||
MaximizeButton.cc | ||
MinimizeButton.cc | ||
plugin.cc | ||
) | ||
|
||
add_library (materialdecoration MODULE | ||
${decoration_SRCS} | ||
) | ||
|
||
target_link_libraries (materialdecoration | ||
PUBLIC | ||
Qt5::Core | ||
Qt5::Gui | ||
KF5::ConfigCore | ||
KF5::ConfigGui | ||
KF5::CoreAddons | ||
KF5::GuiAddons | ||
KF5::WindowSystem | ||
|
||
PRIVATE | ||
KDecoration2::KDecoration | ||
) | ||
|
||
install (TARGETS materialdecoration | ||
DESTINATION ${PLUGIN_INSTALL_DIR}/org.kde.kdecoration2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright (C) 2018 Vlad Zagorodniy <[email protected]> | ||
* | ||
* 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, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* 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. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
// own | ||
#include "CloseButton.h" | ||
#include "Decoration.h" | ||
|
||
// KDecoration | ||
#include <KDecoration2/DecoratedClient> | ||
|
||
// Qt | ||
#include <QPainter> | ||
|
||
namespace Material | ||
{ | ||
|
||
CloseButton::CloseButton(Decoration *decoration, QObject *parent) | ||
: DecorationButton(KDecoration2::DecorationButtonType::Close, decoration, parent) | ||
{ | ||
auto *decoratedClient = decoration->client().data(); | ||
connect(decoratedClient, &KDecoration2::DecoratedClient::closeableChanged, | ||
this, &CloseButton::setVisible); | ||
|
||
connect(this, &CloseButton::hoveredChanged, this, | ||
[this] { | ||
update(); | ||
}); | ||
|
||
const int titleBarHeight = decoration->titleBarHeight(); | ||
const QSize size(qRound(titleBarHeight * 1.33), titleBarHeight); | ||
setGeometry(QRect(QPoint(0, 0), size)); | ||
setVisible(decoratedClient->isCloseable()); | ||
} | ||
|
||
CloseButton::~CloseButton() | ||
{ | ||
} | ||
|
||
void CloseButton::paint(QPainter *painter, const QRect &repaintRegion) | ||
{ | ||
Q_UNUSED(repaintRegion) | ||
|
||
const QRectF buttonRect = geometry(); | ||
QRectF crossRect = QRectF(0, 0, 10, 10); | ||
crossRect.moveCenter(buttonRect.center().toPoint()); | ||
|
||
painter->save(); | ||
|
||
painter->setRenderHints(QPainter::Antialiasing, false); | ||
|
||
// Background. | ||
painter->setPen(Qt::NoPen); | ||
painter->setBrush(backgroundColor()); | ||
painter->drawRect(buttonRect); | ||
|
||
// Foreground. | ||
painter->setPen(foregroundColor()); | ||
painter->setBrush(Qt::NoBrush); | ||
painter->drawLine(crossRect.topLeft(), crossRect.bottomRight()); | ||
painter->drawLine(crossRect.topRight(), crossRect.bottomLeft()); | ||
|
||
painter->restore(); | ||
} | ||
|
||
QColor CloseButton::backgroundColor() const | ||
{ | ||
const auto *deco = qobject_cast<Decoration *>(decoration()); | ||
if (!deco) { | ||
return {}; | ||
} | ||
|
||
if (isPressed()) { | ||
auto *decoratedClient = deco->client().data(); | ||
return decoratedClient->color( | ||
KDecoration2::ColorGroup::Warning, | ||
KDecoration2::ColorRole::Foreground | ||
).lighter(); | ||
} | ||
|
||
if (isHovered()) { | ||
auto *decoratedClient = deco->client().data(); | ||
return decoratedClient->color( | ||
KDecoration2::ColorGroup::Warning, | ||
KDecoration2::ColorRole::Foreground | ||
); | ||
} | ||
|
||
return deco->titleBarBackgroundColor(); | ||
} | ||
|
||
QColor CloseButton::foregroundColor() const | ||
{ | ||
const auto *deco = qobject_cast<Decoration *>(decoration()); | ||
if (!deco) { | ||
return {}; | ||
} | ||
|
||
return deco->titleBarForegroundColor(); | ||
} | ||
|
||
} // namespace Material |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (C) 2018 Vlad Zagorodniy <[email protected]> | ||
* | ||
* 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, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* 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. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
// KDecoration | ||
#include <KDecoration2/DecorationButton> | ||
|
||
namespace Material | ||
{ | ||
|
||
class Decoration; | ||
|
||
class CloseButton : public KDecoration2::DecorationButton | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
CloseButton(Decoration *decoration, QObject *parent = nullptr); | ||
~CloseButton() override; | ||
|
||
void paint(QPainter *painter, const QRect &repaintRegion) override; | ||
|
||
private: | ||
QColor backgroundColor() const; | ||
QColor foregroundColor() const; | ||
}; | ||
|
||
} // namespace Material |
Oops, something went wrong.