LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
colorbutton.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #include "colorbutton.h"
10 #include <QColorDialog>
11 
12 namespace LC::Util
13 {
14  ColorButton::ColorButton (QWidget *parent)
15  : QPushButton { parent }
16  {
17  connect (this,
18  &QPushButton::released,
19  this,
20  &ColorButton::HandleSelector);
21 
22  SetColor (Qt::black);
23  }
24 
25  QColor ColorButton::GetColor () const
26  {
27  return Color_;
28  }
29 
30  void ColorButton::SetColor (const QColor& color)
31  {
32  if (Color_ == color)
33  return;
34 
35  Color_ = color;
36  emit colorChanged (Color_);
37 
38  QPixmap px { iconSize () };
39  px.fill (Color_);
40  setIcon (px);
41  }
42 
43  void ColorButton::HandleSelector ()
44  {
45  const auto color = QColorDialog::getColor (Color_,
46  this,
47  tr ("Select color"),
48  QColorDialog::ShowAlphaChannel);
49  if (!color.isValid ())
50  return;
51 
52  SetColor (color);
53  }
54 }
LC::Util::ColorButton::SetColor
void SetColor(const QColor &color)
Sets the color represented by this button.
Definition: colorbutton.cpp:36
colorbutton.h
LC::Util::ColorButton::GetColor
QColor GetColor() const
Returns the current color represented by this button.
Definition: colorbutton.cpp:31
LC::Util
Definition: icoreproxy.h:33
LC::Util::ColorButton::ColorButton
ColorButton(QWidget *parent=nullptr)
Constructs the button with the given parent.
Definition: colorbutton.cpp:20
LC::Util::ColorButton::colorChanged
void colorChanged(const QColor &color)
Emitted when the color is changed.