diff --git a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
#
-# 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")
diff --git a/cmake/modules/BuildQColorWidgets.cmake b/cmake/modules/BuildQColorWidgets.cmake
deleted file mode 100644
--- a/cmake/modules/BuildQColorWidgets.cmake
+++ /dev/null
@@ -1,36 +0,0 @@
-#
-# Copyright © 2018 Hasan Yavuz Özderya
-#
-# This file is part of serialplot.
-#
-# serialplot 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 3 of the License, or
-# (at your option) any later version.
-#
-# serialplot 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 serialplot. If not, see .
-#
-
-include(ExternalProject)
-
-ExternalProject_Add(QCW
- PREFIX qcw
- GIT_REPOSITORY https://gitlab.com/mattia.basaglia/Qt-Color-Widgets.git
- GIT_TAG 2c49e1bb4e1f591e720e2132cc2aaeef3ba73f14
- CMAKE_CACHE_ARGS "-DCMAKE_CXX_FLAGS:string=-D QTCOLORWIDGETS_STATICALLY_LINKED"
- UPDATE_COMMAND ""
- INSTALL_COMMAND "")
-
-ExternalProject_Get_Property(QCW binary_dir source_dir)
-set(QTCOLORWIDGETS_FLAGS "-D QTCOLORWIDGETS_STATICALLY_LINKED")
-set(QTCOLORWIDGETS_LIBRARY ${binary_dir}/libColorWidgets-qt5.a)
-set(QTCOLORWIDGETS_INCLUDE_DIR ${source_dir}/include)
-
-set(QTCOLORWIDGETS_LIBRARIES ${QTCOLORWIDGETS_LIBRARY})
-set(QTCOLORWIDGETS_INCLUDE_DIRS ${QTCOLORWIDGETS_INCLUDE_DIR})
diff --git a/cmake/modules/FindQtColorWidgets.cmake b/cmake/modules/FindQtColorWidgets.cmake
deleted file mode 100644
--- a/cmake/modules/FindQtColorWidgets.cmake
+++ /dev/null
@@ -1,35 +0,0 @@
-#
-# Copyright © 2017 Hasan Yavuz Özderya
-#
-# This file is part of serialplot.
-#
-# serialplot 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 3 of the License, or
-# (at your option) any later version.
-#
-# serialplot 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 serialplot. If not, see .
-#
-
-# Note: this script is intended for the debian package created for serialplot.
-
-find_library(QTCOLORWIDGETS_LIBRARY "libColorWidgets-qt5.a")
-find_path(QTCOLORWIDGETS_INCLUDE_DIR "color_preview.hpp" PATHS "/usr/include/qtcolorwidgets/" NO_DEFAULT_PATH)
-
-mark_as_advanced(QTCOLORWIDGETS_LIBRARY QTCOLORWIDGETS_INCLUDE_DIR)
-
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(QtColorWidgets DEFAULT_MSG QTCOLORWIDGETS_LIBRARY QTCOLORWIDGETS_INCLUDE_DIR)
-
-if (QTCOLORWIDGETS_FOUND)
- set(QTCOLORWIDGETS_FLAGS "-D QTCOLORWIDGETS_STATICALLY_LINKED")
- mark_as_advanced(QTCOLORWIDGETS_FLAGS)
- set(QTCOLORWIDGETS_LIBRARIES ${QTCOLORWIDGETS_LIBRARY})
- set(QTCOLORWIDGETS_INCLUDE_DIRS ${QTCOLORWIDGETS_INCLUDE_DIR})
-endif (QTCOLORWIDGETS_FOUND)
diff --git a/src/plotcontrolpanel.cpp b/src/plotcontrolpanel.cpp
--- a/src/plotcontrolpanel.cpp
+++ b/src/plotcontrolpanel.cpp
@@ -1,5 +1,5 @@
/*
- Copyright © 2018 Hasan Yavuz Özderya
+ Copyright © 2019 Hasan Yavuz Özderya
This file is part of serialplot.
@@ -21,10 +21,10 @@
#include
#include
#include
+#include
#include
-#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();
+
+ // 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();
}
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 & roles = QVector ())
{
@@ -419,11 +429,7 @@ void PlotControlPanel::setChannelInfoMod
auto mod = ui->tvChannelInfo->model();
QColor color = mod->data(current, Qt::ForegroundRole).value();
-
- // 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
diff --git a/src/plotcontrolpanel.h b/src/plotcontrolpanel.h
--- a/src/plotcontrolpanel.h
+++ b/src/plotcontrolpanel.h
@@ -1,5 +1,5 @@
/*
- 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
diff --git a/src/plotcontrolpanel.ui b/src/plotcontrolpanel.ui
--- a/src/plotcontrolpanel.ui
+++ b/src/plotcontrolpanel.ui
@@ -7,7 +7,7 @@
0
0
704
- 195
+ 220
@@ -69,9 +69,9 @@
QLayout::SetMaximumSize
-
-
+
-
+
0
0
@@ -88,6 +88,15 @@
20
+
+ background-color: rgb(70, 141, 255);
+
+
+
+
+
+ false
+
-
@@ -411,14 +420,6 @@
-
-
- color_widgets::ColorSelector
- QWidget
-
- 1
-
-