Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nheko
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
nheko
Commits
afe381e9
Verified
Commit
afe381e9
authored
2 years ago
by
Nicolas Werner
Browse files
Options
Downloads
Patches
Plain Diff
Remove unused ToggleButton
parent
14f7fe28
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#2908
passed
2 years ago
Stage: build
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CMakeLists.txt
+0
-2
0 additions, 2 deletions
CMakeLists.txt
src/ui/ToggleButton.cpp
+0
-222
0 additions, 222 deletions
src/ui/ToggleButton.cpp
src/ui/ToggleButton.h
+0
-133
0 additions, 133 deletions
src/ui/ToggleButton.h
with
0 additions
and
357 deletions
CMakeLists.txt
+
0
−
2
View file @
afe381e9
...
...
@@ -341,7 +341,6 @@ set(SRC_FILES
src/ui/TextField.cpp
src/ui/Theme.cpp
src/ui/ThemeManager.cpp
src/ui/ToggleButton.cpp
src/ui/UIA.cpp
src/ui/UserProfile.cpp
...
...
@@ -536,7 +535,6 @@ qt5_wrap_cpp(MOC_HEADERS
src/ui/TextField.h
src/ui/Theme.h
src/ui/ThemeManager.h
src/ui/ToggleButton.h
src/ui/UIA.h
src/ui/UserProfile.h
...
...
This diff is collapsed.
Click to expand it.
src/ui/ToggleButton.cpp
deleted
100644 → 0
+
0
−
222
View file @
14f7fe28
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include
<QColor>
#include
<QCoreApplication>
#include
<QEvent>
#include
<QPainter>
#include
"ToggleButton.h"
void
Toggle
::
paintEvent
(
QPaintEvent
*
event
)
{
Q_UNUSED
(
event
);
}
Toggle
::
Toggle
(
QWidget
*
parent
)
:
QAbstractButton
{
parent
}
{
init
();
connect
(
this
,
&
QAbstractButton
::
toggled
,
this
,
&
Toggle
::
setState
);
}
void
Toggle
::
setState
(
bool
isEnabled
)
{
setChecked
(
isEnabled
);
thumb_
->
setShift
(
isEnabled
?
Position
::
Left
:
Position
::
Right
);
setupProperties
();
}
void
Toggle
::
init
()
{
track_
=
new
ToggleTrack
(
this
);
thumb_
=
new
ToggleThumb
(
this
);
setCursor
(
QCursor
(
Qt
::
PointingHandCursor
));
setCheckable
(
true
);
setChecked
(
false
);
setState
(
false
);
setupProperties
();
QCoreApplication
::
processEvents
();
}
void
Toggle
::
setupProperties
()
{
if
(
isEnabled
())
{
Position
position
=
thumb_
->
shift
();
thumb_
->
setThumbColor
(
trackColor
());
if
(
position
==
Position
::
Left
)
track_
->
setTrackColor
(
activeColor
());
else
if
(
position
==
Position
::
Right
)
track_
->
setTrackColor
(
inactiveColor
());
}
update
();
}
void
Toggle
::
setDisabledColor
(
const
QColor
&
color
)
{
disabledColor_
=
color
;
setupProperties
();
emit
disabledColorChanged
();
}
void
Toggle
::
setActiveColor
(
const
QColor
&
color
)
{
activeColor_
=
color
;
setupProperties
();
emit
activeColorChanged
();
}
void
Toggle
::
setInactiveColor
(
const
QColor
&
color
)
{
inactiveColor_
=
color
;
setupProperties
();
emit
inactiveColorChanged
();
}
void
Toggle
::
setTrackColor
(
const
QColor
&
color
)
{
trackColor_
=
color
;
setupProperties
();
emit
trackColorChanged
();
}
ToggleThumb
::
ToggleThumb
(
Toggle
*
parent
)
:
QWidget
{
parent
}
,
toggle_
{
parent
}
,
position_
{
Position
::
Right
}
,
offset_
{
0
}
{
parent
->
installEventFilter
(
this
);
}
void
ToggleThumb
::
setShift
(
Position
position
)
{
if
(
position_
!=
position
)
{
position_
=
position
;
updateOffset
();
}
}
bool
ToggleThumb
::
eventFilter
(
QObject
*
obj
,
QEvent
*
event
)
{
const
QEvent
::
Type
type
=
event
->
type
();
if
(
QEvent
::
Resize
==
type
||
QEvent
::
Move
==
type
)
{
setGeometry
(
toggle_
->
rect
().
adjusted
(
8
,
8
,
-
8
,
-
8
));
updateOffset
();
}
return
QWidget
::
eventFilter
(
obj
,
event
);
}
void
ToggleThumb
::
paintEvent
(
QPaintEvent
*
event
)
{
Q_UNUSED
(
event
)
QPainter
painter
(
this
);
painter
.
setRenderHint
(
QPainter
::
Antialiasing
);
QBrush
brush
;
brush
.
setStyle
(
Qt
::
SolidPattern
);
brush
.
setColor
(
toggle_
->
isEnabled
()
?
thumbColor_
:
Qt
::
white
);
painter
.
setBrush
(
brush
);
painter
.
setPen
(
Qt
::
NoPen
);
int
s
;
QRectF
r
;
s
=
height
()
-
10
;
r
=
QRectF
(
5
+
offset_
,
5
,
s
,
s
);
painter
.
drawEllipse
(
r
);
if
(
!
toggle_
->
isEnabled
())
{
brush
.
setColor
(
toggle_
->
disabledColor
());
painter
.
setBrush
(
brush
);
painter
.
drawEllipse
(
r
);
}
}
void
ToggleThumb
::
updateOffset
()
{
const
QSize
s
(
size
());
offset_
=
position_
==
Position
::
Left
?
static_cast
<
qreal
>
(
s
.
width
()
-
s
.
height
())
:
0
;
update
();
}
ToggleTrack
::
ToggleTrack
(
Toggle
*
parent
)
:
QWidget
{
parent
}
,
toggle_
{
parent
}
{
Q_ASSERT
(
parent
);
parent
->
installEventFilter
(
this
);
}
void
ToggleTrack
::
setTrackColor
(
const
QColor
&
color
)
{
trackColor_
=
color
;
emit
trackColorChanged
();
update
();
}
bool
ToggleTrack
::
eventFilter
(
QObject
*
obj
,
QEvent
*
event
)
{
const
QEvent
::
Type
type
=
event
->
type
();
if
(
QEvent
::
Resize
==
type
||
QEvent
::
Move
==
type
)
{
setGeometry
(
toggle_
->
rect
());
}
return
QWidget
::
eventFilter
(
obj
,
event
);
}
void
ToggleTrack
::
paintEvent
(
QPaintEvent
*
event
)
{
Q_UNUSED
(
event
)
QPainter
painter
(
this
);
painter
.
setRenderHint
(
QPainter
::
Antialiasing
);
QBrush
brush
;
if
(
toggle_
->
isEnabled
())
{
brush
.
setColor
(
trackColor_
);
painter
.
setOpacity
(
0.8
);
}
else
{
brush
.
setColor
(
toggle_
->
disabledColor
());
painter
.
setOpacity
(
0.6
);
}
brush
.
setStyle
(
Qt
::
SolidPattern
);
painter
.
setBrush
(
brush
);
painter
.
setPen
(
Qt
::
NoPen
);
const
int
h
=
height
()
/
2
;
const
QRect
r
(
0
,
h
/
2
,
width
(),
h
);
painter
.
drawRoundedRect
(
r
.
adjusted
(
14
,
4
,
-
14
,
-
4
),
h
/
2
-
4
,
h
/
2
-
4
);
}
This diff is collapsed.
Click to expand it.
src/ui/ToggleButton.h
deleted
100644 → 0
+
0
−
133
View file @
14f7fe28
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include
<QAbstractButton>
#include
<QColor>
class
ToggleTrack
;
class
ToggleThumb
;
enum
class
Position
{
Left
,
Right
};
class
Toggle
:
public
QAbstractButton
{
Q_OBJECT
Q_PROPERTY
(
QColor
activeColor
WRITE
setActiveColor
READ
activeColor
NOTIFY
activeColorChanged
)
Q_PROPERTY
(
QColor
disabledColor
WRITE
setDisabledColor
READ
disabledColor
NOTIFY
disabledColorChanged
)
Q_PROPERTY
(
QColor
inactiveColor
WRITE
setInactiveColor
READ
inactiveColor
NOTIFY
inactiveColorChanged
)
Q_PROPERTY
(
QColor
trackColor
WRITE
setTrackColor
READ
trackColor
NOTIFY
trackColorChanged
)
public:
Toggle
(
QWidget
*
parent
=
nullptr
);
void
setState
(
bool
isEnabled
);
void
setActiveColor
(
const
QColor
&
color
);
void
setDisabledColor
(
const
QColor
&
color
);
void
setInactiveColor
(
const
QColor
&
color
);
void
setTrackColor
(
const
QColor
&
color
);
QColor
activeColor
()
const
{
return
activeColor_
;
};
QColor
disabledColor
()
const
{
return
disabledColor_
;
};
QColor
inactiveColor
()
const
{
return
inactiveColor_
;
};
QColor
trackColor
()
const
{
return
trackColor_
.
isValid
()
?
trackColor_
:
QColor
(
0xee
,
0xee
,
0xee
);
};
QSize
sizeHint
()
const
override
{
return
QSize
(
64
,
48
);
};
protected
:
void
paintEvent
(
QPaintEvent
*
event
)
override
;
signals
:
void
activeColorChanged
();
void
disabledColorChanged
();
void
inactiveColorChanged
();
void
trackColorChanged
();
private
:
void
init
();
void
setupProperties
();
ToggleTrack
*
track_
;
ToggleThumb
*
thumb_
;
QColor
disabledColor_
;
QColor
activeColor_
;
QColor
inactiveColor_
;
QColor
trackColor_
;
};
class
ToggleThumb
:
public
QWidget
{
Q_OBJECT
Q_PROPERTY
(
QColor
thumbColor
WRITE
setThumbColor
READ
thumbColor
NOTIFY
thumbColorChanged
)
public:
ToggleThumb
(
Toggle
*
parent
);
Position
shift
()
const
{
return
position_
;
};
qreal
offset
()
const
{
return
offset_
;
};
QColor
thumbColor
()
const
{
return
thumbColor_
;
};
void
setShift
(
Position
position
);
void
setThumbColor
(
const
QColor
&
color
)
{
thumbColor_
=
color
;
emit
thumbColorChanged
();
update
();
};
protected
:
bool
eventFilter
(
QObject
*
obj
,
QEvent
*
event
)
override
;
void
paintEvent
(
QPaintEvent
*
event
)
override
;
signals
:
void
thumbColorChanged
();
private
:
void
updateOffset
();
Toggle
*
const
toggle_
;
QColor
thumbColor_
;
Position
position_
;
qreal
offset_
;
};
class
ToggleTrack
:
public
QWidget
{
Q_OBJECT
Q_PROPERTY
(
QColor
trackColor
WRITE
setTrackColor
READ
trackColor
NOTIFY
trackColor
)
public:
ToggleTrack
(
Toggle
*
parent
);
void
setTrackColor
(
const
QColor
&
color
);
QColor
trackColor
()
const
{
return
trackColor_
;
};
protected
:
bool
eventFilter
(
QObject
*
obj
,
QEvent
*
event
)
override
;
void
paintEvent
(
QPaintEvent
*
event
)
override
;
signals
:
void
trackColorChanged
();
private
:
Toggle
*
const
toggle_
;
QColor
trackColor_
;
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment