Skip to content
This repository was archived by the owner on Aug 17, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,37 @@ formats.

Colorpick is managed using the [lightweight project management policy][1].

[1]: http://agateau.com/2014/lightweight-project-management
Currently, working only under X11 based systems.

## Requirements

- CMake
- Qt 5
- KF5GuiAddons
- KF5WidgetsAddons
- Qt 5/6
- [KGuiAddons][2]
- [KWidgetsAddons][3]

## Installation

Create a build directory and change to it:

mkdir build
cd build
```bash
mkdir build
cd build
```

Run CMake and build:
By default, Qt5 is used for build, otherwise change it by adding `-DPROJECT_QT_VERSION=6`
to the following CMake configure command:

cmake path/to/colorpick
make
```bash
cmake path/to/colorpick
make
```

Install (must be run as root if installing to /usr or /usr/local):

make install
```bash
make install
```

## Author

Expand All @@ -49,3 +56,8 @@ Aurélien Gâteau
## License

BSD


[1]: http://agateau.com/2014/lightweight-project-management
[2]: https://invent.kde.org/frameworks/kguiaddons/
[3]: https://invent.kde.org/frameworks/kwidgetsaddons/
27 changes: 14 additions & 13 deletions src/coloreditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void ColorEditor::setColor(const QColor &color)
if (mColor != color) {
mColor = color;
updateFromColor();
colorChanged(mColor);
emit colorChanged(mColor);
}
}

Expand Down Expand Up @@ -156,22 +156,23 @@ void ColorEditor::startPicking()

void ColorEditor::fillCopyMenu()
{
#if QT_VERSION < 0x060000
typedef qreal float_qt; // double
#else
typedef float float_qt;
#endif
mCopyMenu->clear();
int r, g, b;
qreal rf, gf, bf;
float_qt rf, gf, bf;
mColor.getRgb(&r, &g, &b);
mColor.getRgbF(&rf, &gf, &bf);

auto myfloat = [](qreal value) {
return QString::number(value, 'g', 3);
};

auto hex = [](int value) {
return QString::number(value, 16).rightJustified(2, '0');
};
auto constexpr ftoa = [](float value) { return QString::number(value, 'g', 3); };
auto constexpr hex = [](int value) { return QString::number(value, 16).rightJustified(2, '0'); };
auto constexpr itoa = [](int value) { return QString::number(value); };

auto addColorAction = [this](const QString &text, const QString &value) {
QString fullText = ColorEditor::tr("%1: %2").arg(text, value);
QString fullText = QString("%1: %2").arg(text, value);
QAction *action = mCopyMenu->addAction(fullText);
connect(action, &QAction::triggered, this, [value]() {
QApplication::clipboard()->setText(value);
Expand All @@ -181,7 +182,7 @@ void ColorEditor::fillCopyMenu()
addColorAction(tr("Inkscape"), hex(r) + hex(g) + hex(b) + hex(255));
addColorAction(tr("Hexa with #"), "#" + hex(r) + hex(g) + hex(b));
addColorAction(tr("Quoted hexa with #"), "\"#" + hex(r) + hex(g) + hex(b) + "\"");
addColorAction(tr("Float values"), QString("%1, %2, %3").arg(myfloat(rf), myfloat(gf), myfloat(bf)));
addColorAction(tr("Int values"), QString("%1, %2, %3").arg(r).arg(g).arg(b));
addColorAction(tr("CSS RGB Value"), QString("rgb(%1, %2, %3)").arg(r).arg(g).arg(b));
addColorAction(tr("Float values"), QString("%1, %2, %3").arg(ftoa(rf), ftoa(gf), ftoa(bf)));
addColorAction(tr("Int values"), QString("%1, %2, %3").arg(itoa(r), itoa(g), itoa(b)));
addColorAction(tr("CSS RGB Value"), QString("rgb(%1, %2, %3)").arg(itoa(r), itoa(g), itoa(b)));
}
16 changes: 12 additions & 4 deletions src/colorpicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include <QApplication>
#include <QCursor>
#include <QDebug>
#if QT_VERSION < 0x060000
#include <QDesktopWidget>
#endif
#include <QImage>
#include <QKeyEvent>
#include <QMouseEvent>
Expand Down Expand Up @@ -94,28 +96,32 @@ void ColorPicker::keyPressEvent(QKeyEvent *event)
void ColorPicker::paintEvent(QPaintEvent *event)
{
QPainter painter(this);

// Draw content
QPixmap pix = mPixmap.scaled(GRAB_SIZE * mScaleFactor * MAGNIFY,
GRAB_SIZE * mScaleFactor * MAGNIFY);
painter.drawPixmap(0, 0, pix);

// Draw outer border
painter.setPen(Qt::darkGray);
QRect rct = rect().adjusted(0, 0, -1, -1);
painter.drawRect(rct);

// Draw inner border
painter.setPen(Qt::white);
rct = rct.adjusted(1, 1, -1, -1);
painter.drawRect(rct);

// Draw centered cursor
painter.setCompositionMode(QPainter::RasterOp_SourceXorDestination);
painter.setPen(Qt::white);
painter.drawRect(GRAB_RADIUS * MAGNIFY - 1, GRAB_RADIUS * MAGNIFY - 1, MAGNIFY + 1, MAGNIFY + 1);
}

void ColorPicker::emitColorChanged()
{
QImage image = mPixmap.toImage();
QColor color = image.pixelColor(GRAB_RADIUS * mScaleFactor, GRAB_RADIUS * mScaleFactor);
colorChanged(color);
emit colorChanged(color);
}

void ColorPicker::updatePosition()
Expand All @@ -141,9 +147,11 @@ void ColorPicker::updatePosition()
}

move(newPos);

#if QT_VERSION < 0x060000
WId wid = QApplication::desktop()->winId();

#else
WId wid = 0;
#endif
mPixmap = screen->grabWindow(wid, pos.x() - GRAB_SIZE / 2, pos.y() - GRAB_SIZE / 2, GRAB_SIZE, GRAB_SIZE);
update();
}
1 change: 0 additions & 1 deletion src/contrastpreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ void ContrastPreview::setForegroundColor(const QColor &color)
}
}


void ContrastPreview::updatePreview()
{
updateRatioLabel();
Expand Down
1 change: 0 additions & 1 deletion src/hsvcolorspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ HsvColorSpace *HsvColorSpace::instance()

HsvColorSpace::HsvColorSpace()
{

}

QString HsvColorSpace::name(int idx) const
Expand Down
1 change: 0 additions & 1 deletion src/imagegradientselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
ImageGradientSelector::ImageGradientSelector(QWidget *parent)
: KSelector(parent)
{

}

void ImageGradientSelector::setImage(const QImage &image)
Expand Down
1 change: 0 additions & 1 deletion src/rgbcolorspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ RgbColorSpace *RgbColorSpace::instance()

RgbColorSpace::RgbColorSpace()
{

}

QString RgbColorSpace::name(int idx) const
Expand Down
2 changes: 1 addition & 1 deletion src/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Window : public QMainWindow
{
Q_OBJECT
public:
explicit Window(QWidget *parent = 0);
explicit Window(QWidget *parent = nullptr);

private:
ColorEditor *mBgEditor;
Expand Down