Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F622846
ColorButton.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
ColorButton.cpp
View Options
#include
"ColorButton.h"
#include
<ColorDialog.h>
#include
<QPainter>
#include
<QProxyStyle>
#include
<QStyleOption>
#include
"common/misc.h"
ColorButton
::
ColorButton
(
QWidget
*
parent
)
:
QToolButton
(
parent
)
{
color_
=
Qt
::
red
;
connect
(
this
,
&
ColorButton
::
clicked
,
[
&
](){
QColor
c
=
color
();
ColorDialog
dlg
(
this
,
c
);
if
(
dlg
.
exec
()
==
QDialog
::
Accepted
)
{
c
=
dlg
.
color
();
setColor
(
c
);
}
});
}
/**
* @brief 色を取得
* @return
*/
QColor
ColorButton
::
color
()
const
{
return
color_
;
}
/**
* @brief 色を設定
* @param color
*/
void
ColorButton
::
setColor
(
QColor
const
&
color
)
{
color_
=
color
;
update
();
}
/**
* @brief 描画
* @param event
*/
void
ColorButton
::
paintEvent
(
QPaintEvent
*
event
)
{
QPainter
pr
(
this
);
QStyleOptionToolButton
o
;
QStyleOptionButton
o2
;
initStyleOption
(
&
o
);
o2
.
rect
=
o
.
rect
;
o2
.
state
=
o
.
state
;
int
h
=
o2
.
rect
.
height
();
// 色の矩形を描画
misc
::
drawFrame
(
&
pr
,
0
,
1
,
h
-
2
,
h
-
2
,
Qt
::
black
);
pr
.
fillRect
(
1
,
2
,
h
-
4
,
h
-
4
,
color
());
// ボタン枠を描画
o2
.
rect
.
adjust
(
h
+
2
,
0
,
0
,
0
);
style
()
->
drawControl
(
QStyle
::
CE_PushButtonBevel
,
&
o2
,
&
pr
,
this
);
// ボタンテキストを描画
o2
.
rect
.
adjust
(
4
,
0
,
0
,
0
);
style
()
->
drawItemText
(
&
pr
,
o2
.
rect
,
Qt
::
AlignLeft
|
Qt
::
AlignVCenter
,
palette
(),
isEnabled
(),
o
.
text
);
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sat, Nov 14, 8:35 PM (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
127721
Default Alt Text
ColorButton.cpp (1 KB)
Attached To
Mode
R77 Guitar
Attached
Detach File
Event Timeline