Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added various color formats to ColorPicker plugin

  • Loading branch information...
commit 268134a1ef12f8d9b68fbc122dc43bd5c2fda0b8 1 parent df8f52b
@Mezomish authored
View
5 plugins/colorpicker/CMakeLists.txt
@@ -1,15 +1,18 @@
# colorpicker
set( colorpicker_SRC
ColorPickerPlugin.cpp
+ ColorFormatDlg.cpp
)
QT4_ADD_RESOURCES( colorpicker_RES colorpicker.qrc )
-QT4_WRAP_CPP( colorpicker_MOC ColorPickerPlugin.h )
+QT4_WRAP_CPP( colorpicker_MOC ColorPickerPlugin.h ColorFormatDlg.h )
+QT4_WRAP_UI( colorpicker_UI ColorFormatDlg.ui)
add_library( colorpicker SHARED
${colorpicker_SRC}
${colorpicker_MOC}
${colorpicker_RES}
+ ${colorpicker_UI}
)
target_link_libraries( colorpicker
View
47 plugins/colorpicker/ColorFormatDlg.cpp
@@ -0,0 +1,47 @@
+#include "ColorFormatDlg.h"
+
+#include <PluginSettings.h>
+
+ColorFormatDlg::ColorFormatDlg( JuffPlugin* plugin, const QColor& color, QWidget* parent) : QDialog(parent) {
+ _ui.setupUi( this );
+
+ _plugin = plugin;
+
+ connect( _ui.buttonBox, SIGNAL(accepted()), SLOT(accept()) );
+ connect( _ui.buttonBox, SIGNAL(rejected()), SLOT(reject()) );
+
+ int r, g, b;
+ color.getRgb( &r, &g, &b );
+
+ _ui.btnHtml->setText( color.name() );
+ _ui.btnHex->setText( color.name().replace("#", "0x") );
+ _ui.btnHexSplitted->setText( QString().sprintf("0x%02hX, 0x%02hX, 0x%02hX", r, g, b) );
+ _ui.btnSplitted->setText( QString().sprintf("%i, %i, %i", r, g, b) );
+
+ _ui.buttonGroup->setId( _ui.btnHtml, 0 );
+ _ui.buttonGroup->setId( _ui.btnHex, 1 );
+ _ui.buttonGroup->setId( _ui.btnHexSplitted, 2 );
+ _ui.buttonGroup->setId( _ui.btnSplitted, 3 );
+
+// _ui.btnHtml->setChecked( true );
+ int id = PluginSettings::getInt( plugin, "format", 0 );
+ QAbstractButton* btn = _ui.buttonGroup->button( id );
+ if ( btn != 0 ) {
+ btn->setChecked( true );
+ }
+ else {
+ _ui.btnHtml->setChecked( true );
+ }
+}
+
+QString ColorFormatDlg::colorStr() const {
+ QAbstractButton* checkedBtn = _ui.buttonGroup->checkedButton();
+ if ( checkedBtn != 0 ) {
+ int id = _ui.buttonGroup->checkedId();
+ PluginSettings::set( _plugin, "format", id );
+ return checkedBtn->text();
+ }
+ else {
+ return "";
+ }
+}
View
21 plugins/colorpicker/ColorFormatDlg.h
@@ -0,0 +1,21 @@
+#ifndef __COLOR_FORMAT_DLG_H__
+#define __COLOR_FORMAT_DLG_H__
+
+class JuffPlugin;
+
+#include <QDialog>
+
+#include "ui_ColorFormatDlg.h"
+
+class ColorFormatDlg : public QDialog {
+Q_OBJECT
+public:
+ ColorFormatDlg(JuffPlugin* plugin, const QColor&, QWidget * parent = 0);
+ QString colorStr() const;
+
+private:
+ Ui::ColorFormatDlg _ui;
+ JuffPlugin* _plugin;
+};
+
+#endif // __COLOR_FORMAT_DLG_H__
View
120 plugins/colorpicker/ColorFormatDlg.ui
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ColorFormatDlg</class>
+ <widget class="QDialog" name="ColorFormatDlg">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>209</width>
+ <height>179</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Color format</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QRadioButton" name="btnHtml">
+ <property name="text">
+ <string>RadioButton</string>
+ </property>
+ <attribute name="buttonGroup">
+ <string>buttonGroup</string>
+ </attribute>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="btnHex">
+ <property name="text">
+ <string>RadioButton</string>
+ </property>
+ <attribute name="buttonGroup">
+ <string>buttonGroup</string>
+ </attribute>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="btnHexSplitted">
+ <property name="text">
+ <string>RadioButton</string>
+ </property>
+ <attribute name="buttonGroup">
+ <string>buttonGroup</string>
+ </attribute>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="btnSplitted">
+ <property name="text">
+ <string>RadioButton</string>
+ </property>
+ <attribute name="buttonGroup">
+ <string>buttonGroup</string>
+ </attribute>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>ColorFormatDlg</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>ColorFormatDlg</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+ <buttongroups>
+ <buttongroup name="buttonGroup"/>
+ </buttongroups>
+</ui>
View
18 plugins/colorpicker/ColorPickerPlugin.cpp
@@ -5,8 +5,11 @@
#include <QtGui/QColorDialog>
#include <Document.h>
+#include <PluginSettings.h>
#include <Log.h>
+#include "ColorFormatDlg.h"
+
ColorPickerPlugin::ColorPickerPlugin() : QObject(), JuffPlugin() {
_pickColorAct = new QAction(QIcon(":icon32"), "Pick a color", this);
connect(_pickColorAct, SIGNAL(triggered()), SLOT(pickColor()));
@@ -44,11 +47,18 @@ Juff::ActionList ColorPickerPlugin::mainMenuActions(Juff::MenuID id) const {
}
void ColorPickerPlugin::pickColor() {
- QColor color = QColorDialog::getColor(Qt::white, api()->mainWindow());
+ QColor lastColor = QColor( PluginSettings::getString( this, "lastColor", "#ffffff" ) );
+ QColor color = QColorDialog::getColor( lastColor, api()->mainWindow() );
if ( color.isValid() ) {
- Juff::Document* doc = api()->currentDocument();
- if ( !doc->isNull() ) {
- doc->replaceSelectedText(color.name());
+ PluginSettings::set( this, "lastColor", color.name() );
+
+ ColorFormatDlg dlg( this, color, api()->mainWindow() );
+ if ( dlg.exec() == QDialog::Accepted ) {
+ QString str = dlg.colorStr();
+ Juff::Document* doc = api()->currentDocument();
+ if ( !doc->isNull() ) {
+ doc->replaceSelectedText( str );
+ }
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.