X-Git-Url: http://git.code-monkey.de/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fwidgets%2Fcolourbutton.cpp;fp=pv%2Fwidgets%2Fcolourbutton.cpp;h=0000000000000000000000000000000000000000;hp=01a22b67d165b85a48298aa3a45b5294fc64d612;hb=641574bcc118be0b6dc3a65039ab3497f9d7241a;hpb=5e685656d6686eb66a39450d1b324f6382fc60c5 diff --git a/pv/widgets/colourbutton.cpp b/pv/widgets/colourbutton.cpp deleted file mode 100644 index 01a22b6..0000000 --- a/pv/widgets/colourbutton.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * This file is part of the PulseView project. - * - * Copyright (C) 2013 Joel Holdsworth - * - * 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 . - */ - -#include "colourbutton.hpp" - -#include - -#include -#include - -namespace pv { -namespace widgets { - -const int ColourButton::SwatchMargin = 7; - -ColourButton::ColourButton(int rows, int cols, QWidget *parent) : - QPushButton("", parent), - popup_(rows, cols, this) -{ - connect(this, SIGNAL(clicked(bool)), this, SLOT(on_clicked(bool))); - connect(&popup_, SIGNAL(selected(int, int)), - this, SLOT(on_selected(int, int))); -} - -ColourPopup& ColourButton::popup() -{ - return popup_; -} - -const QColor& ColourButton::colour() const -{ - return cur_colour_; -} - -void ColourButton::set_colour(QColor colour) -{ - cur_colour_ = colour; - - const unsigned int rows = popup_.well_array().numRows(); - const unsigned int cols = popup_.well_array().numCols(); - - for (unsigned int r = 0; r < rows; r++) - for (unsigned int c = 0; c < cols; c++) - if (popup_.well_array().cellBrush(r, c).color() == colour) { - popup_.well_array().setSelected(r, c); - popup_.well_array().setCurrent(r, c); - return; - } -} - -void ColourButton::set_palette(const QColor *const palette) -{ - assert(palette); - - const unsigned int rows = popup_.well_array().numRows(); - const unsigned int cols = popup_.well_array().numCols(); - - for (unsigned int r = 0; r < rows; r++) - for (unsigned int c = 0; c < cols; c++) - popup_.well_array().setCellBrush(r, c, - QBrush(palette[r * cols + c])); -} - -void ColourButton::on_clicked(bool) -{ - popup_.set_position(mapToGlobal(rect().center()), Popup::Bottom); - popup_.show(); -} - -void ColourButton::on_selected(int row, int col) -{ - cur_colour_ = popup_.well_array().cellBrush(row, col).color(); - selected(cur_colour_); -} - -void ColourButton::paintEvent(QPaintEvent *event) -{ - QPushButton::paintEvent(event); - - QPainter p(this); - - const QRect r = rect().adjusted(SwatchMargin, SwatchMargin, - -SwatchMargin, -SwatchMargin); - p.setPen(QApplication::palette().color(QPalette::Dark)); - p.setBrush(QBrush(cur_colour_)); - p.drawRect(r); -} - -} // namespace widgets -} // namespace pv