Changeset - ed444750d8c4
[Not reviewed]
default
2 4 0
Hasan Yavuz ÖZDERYA - 7 years ago 2019-01-07 23:27:46
hy@ozderya.net
removed dependency to qtcolorwidgets library

color selection is implemented with a qpushbutton and qcolordialog
6 files changed with 53 insertions and 130 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
#
 
# Copyright © 2018 Hasan Yavuz Özderya
 
# Copyright © 2019 Hasan Yavuz Özderya
 
#
 
# This file is part of serialplot.
 
#
 
@@ -44,23 +44,11 @@ else (BUILD_QWT)
 
    find_package(Qwt 6.1 REQUIRED)
 
endif (BUILD_QWT)
 

	
 
# If set, cmake will download QtColorWidgets over git, build and use it as a static library.
 
set(BUILD_QTCOLORWIDGETS true CACHE BOOL "Download and build QtColorWidgets library automatically.")
 
if (BUILD_QTCOLORWIDGETS)
 
  include(BuildQColorWidgets)
 
else ()
 
  find_package(QtColorWidgets REQUIRED)
 
endif ()
 

	
 
# includes
 
include_directories("./src"
 
  ${QWT_INCLUDE_DIR}
 
  ${QTCOLORWIDGETS_INCLUDE_DIRS}
 
  )
 

	
 
# flags
 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${QTCOLORWIDGETS_FLAGS}")
 

	
 
# wrap UI and resource files
 
qt5_wrap_ui(UI_FILES
 
  src/mainwindow.ui
 
@@ -153,7 +141,6 @@ add_executable(${PROGRAM_NAME} WIN32
 
# Use the Widgets module from Qt 5.
 
target_link_libraries(${PROGRAM_NAME}
 
  ${QWT_LIBRARY}
 
  ${QTCOLORWIDGETS_LIBRARIES}
 
  )
 
qt5_use_modules(${PROGRAM_NAME} Widgets SerialPort Network)
 

	
 
@@ -161,10 +148,6 @@ if (BUILD_QWT)
 
  add_dependencies(${PROGRAM_NAME} QWT)
 
endif ()
 

	
 
if (BUILD_QTCOLORWIDGETS)
 
  add_dependencies(${PROGRAM_NAME} QCW)
 
endif ()
 

	
 
# set compiler flags
 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
 

	
cmake/modules/BuildQColorWidgets.cmake
Show inline comments
 
deleted file
cmake/modules/FindQtColorWidgets.cmake
Show inline comments
 
deleted file
src/plotcontrolpanel.cpp
Show inline comments
 
/*
 
  Copyright © 2018 Hasan Yavuz Özderya
 
  Copyright © 2019 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
@@ -21,10 +21,10 @@
 
#include <QMessageBox>
 
#include <QCheckBox>
 
#include <QStyledItemDelegate>
 
#include <QColorDialog>
 

	
 
#include <math.h>
 

	
 
#include "color_selector.hpp"
 
#include "plotcontrolpanel.h"
 
#include "ui_plotcontrolpanel.h"
 
#include "setting_defines.h"
 
@@ -162,9 +162,9 @@ PlotControlPanel::PlotControlPanel(QWidg
 
                     this, SLOT(onRangeSelected()));
 

	
 
    // color selector starts disabled until a channel is selected
 
    ui->colorSelector->setColor(QColor(0,0,0,0));
 
    ui->colorSelector->setDisplayMode(color_widgets::ColorPreview::AllAlpha);
 
    ui->colorSelector->setDisabled(true);
 
    ui->pbColorSel->setDisabled(true);
 
    setSelectorColor(QColor(0,0,0,0));
 
    connect(ui->pbColorSel, &QPushButton::clicked, this, &PlotControlPanel::onColorSelect);
 

	
 
    // reset buttons
 
    resetAct.setToolTip(tr("Reset channel names and colors"));
 
@@ -241,6 +241,30 @@ bool PlotControlPanel::askNSConfirmation
 
    return mb.exec() == QMessageBox::Apply;
 
}
 

	
 
void PlotControlPanel::setSelectorColor(QColor color)
 
{
 
    ui->pbColorSel->setStyleSheet(QString("background-color: %1;").arg(color.name()));
 
}
 

	
 
void PlotControlPanel::onColorSelect()
 
{
 
    auto selection = ui->tvChannelInfo->selectionModel()->currentIndex();
 
    // no selection
 
    if (!selection.isValid()) return;
 

	
 
    // current color
 
    auto model = ui->tvChannelInfo->model();
 
    QColor color = model->data(selection, Qt::ForegroundRole).value<QColor>();
 

	
 
    // show dialog
 
    color = QColorDialog::getColor(color, this);
 

	
 
    if (color.isValid())        // color is set to invalid if user cancels
 
    {
 
        ui->tvChannelInfo->model()->setData(selection, color, Qt::ForegroundRole);
 
    }
 
}
 

	
 
void PlotControlPanel::onAutoScaleChecked(bool checked)
 
{
 
    if (checked)
 
@@ -373,19 +397,16 @@ void PlotControlPanel::setChannelInfoMod
 

	
 
                if (current.isValid())
 
                {
 
                    ui->colorSelector->setEnabled(true);
 
                    ui->pbColorSel->setEnabled(true);
 
                    auto model = ui->tvChannelInfo->model();
 
                    color = model->data(current, Qt::ForegroundRole).value<QColor>();
 
                }
 
                else
 
                {
 
                    ui->colorSelector->setDisabled(true);
 
                    ui->pbColorSel->setDisabled(true);
 
                }
 

	
 
                // temporarily block signals because `setColor` emits `colorChanged`
 
                bool wasBlocked = ui->colorSelector->blockSignals(true);
 
                ui->colorSelector->setColor(color);
 
                ui->colorSelector->blockSignals(wasBlocked);
 
                setSelectorColor(color);
 
            });
 

	
 
    connect(ui->tvChannelInfo->selectionModel(), &QItemSelectionModel::selectionChanged,
 
@@ -393,22 +414,11 @@ void PlotControlPanel::setChannelInfoMod
 
            {
 
                if (!selected.length())
 
                {
 
                    ui->colorSelector->setDisabled(true);
 

	
 
                    // temporarily block signals because `setColor` emits `colorChanged`
 
                    bool wasBlocked = ui->colorSelector->blockSignals(true);
 
                    ui->colorSelector->setColor(QColor(0,0,0,0));
 
                    ui->colorSelector->blockSignals(wasBlocked);
 
                    ui->pbColorSel->setDisabled(true);
 
                    setSelectorColor(QColor(0,0,0,0));
 
                }
 
            });
 

	
 
    connect(ui->colorSelector, &color_widgets::ColorSelector::colorChanged,
 
            [this](QColor color)
 
            {
 
                auto index = ui->tvChannelInfo->selectionModel()->currentIndex();
 
                ui->tvChannelInfo->model()->setData(index, color, Qt::ForegroundRole);
 
            });
 

	
 
    connect(model, &QAbstractItemModel::dataChanged,
 
            [this](const QModelIndex & topLeft, const QModelIndex & bottomRight, const QVector<int> & roles = QVector<int> ())
 
            {
 
@@ -419,11 +429,7 @@ void PlotControlPanel::setChannelInfoMod
 

	
 
                auto mod = ui->tvChannelInfo->model();
 
                QColor color = mod->data(current, Qt::ForegroundRole).value<QColor>();
 

	
 
                // temporarily block signals because `setColor` emits `colorChanged`
 
                bool wasBlocked = ui->colorSelector->blockSignals(true);
 
                ui->colorSelector->setColor(color);
 
                ui->colorSelector->blockSignals(wasBlocked);
 
                setSelectorColor(color);
 
            });
 

	
 
    // reset actions
src/plotcontrolpanel.h
Show inline comments
 
/*
 
  Copyright © 2018 Hasan Yavuz Özderya
 
  Copyright © 2019 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
@@ -79,6 +79,9 @@ private:
 
    /// Show a confirmation dialog before setting #samples to a big value
 
    bool askNSConfirmation(int value);
 

	
 
    /// Set the color displayed by color selector button
 
    void setSelectorColor(QColor color);
 

	
 
private slots:
 
    void onNumOfSamples(int value);
 
    void onAutoScaleChecked(bool checked);
 
@@ -87,6 +90,7 @@ private slots:
 
    void onIndexChecked(bool checked);
 
    void onXScaleChanged();
 
    void onPlotWidthChanged();
 
    void onColorSelect();
 
};
 

	
 
#endif // PLOTCONTROLPANEL_H
src/plotcontrolpanel.ui
Show inline comments
 
@@ -7,7 +7,7 @@
 
    <x>0</x>
 
    <y>0</y>
 
    <width>704</width>
 
    <height>195</height>
 
    <height>220</height>
 
   </rect>
 
  </property>
 
  <property name="windowTitle">
 
@@ -69,9 +69,9 @@
 
         <enum>QLayout::SetMaximumSize</enum>
 
        </property>
 
        <item>
 
         <widget class="color_widgets::ColorSelector" name="colorSelector" native="true">
 
         <widget class="QPushButton" name="pbColorSel">
 
          <property name="sizePolicy">
 
           <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
 
           <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
 
            <horstretch>0</horstretch>
 
            <verstretch>0</verstretch>
 
           </sizepolicy>
 
@@ -88,6 +88,15 @@
 
            <height>20</height>
 
           </size>
 
          </property>
 
          <property name="styleSheet">
 
           <string notr="true">background-color: rgb(70, 141, 255);</string>
 
          </property>
 
          <property name="text">
 
           <string/>
 
          </property>
 
          <property name="flat">
 
           <bool>false</bool>
 
          </property>
 
         </widget>
 
        </item>
 
        <item>
 
@@ -411,14 +420,6 @@
 
   </item>
 
  </layout>
 
 </widget>
 
 <customwidgets>
 
  <customwidget>
 
   <class>color_widgets::ColorSelector</class>
 
   <extends>QWidget</extends>
 
   <header>color_selector.hpp</header>
 
   <container>1</container>
 
  </customwidget>
 
 </customwidgets>
 
 <resources/>
 
 <connections/>
 
</ui>
0 comments (0 inline, 0 general)