diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 84da08d7b7fcda12c85caeb5a10b4903770a6f69 (patch) | |
tree | 2a6aea76f2dfffb4cc04bb907c4725af94f70e72 /kicker-applets/kolourpicker | |
download | tdeaddons-84da08d7b7fcda12c85caeb5a10b4903770a6f69.tar.gz tdeaddons-84da08d7b7fcda12c85caeb5a10b4903770a6f69.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeaddons@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kicker-applets/kolourpicker')
-rw-r--r-- | kicker-applets/kolourpicker/Makefile.am | 23 | ||||
-rw-r--r-- | kicker-applets/kolourpicker/TODO | 1 | ||||
-rw-r--r-- | kicker-applets/kolourpicker/kolourpicker.cpp | 382 | ||||
-rw-r--r-- | kicker-applets/kolourpicker/kolourpicker.desktop | 145 | ||||
-rw-r--r-- | kicker-applets/kolourpicker/kolourpicker.h | 70 | ||||
-rw-r--r-- | kicker-applets/kolourpicker/simplebutton.cpp | 256 | ||||
-rw-r--r-- | kicker-applets/kolourpicker/simplebutton.h | 89 |
7 files changed, 966 insertions, 0 deletions
diff --git a/kicker-applets/kolourpicker/Makefile.am b/kicker-applets/kolourpicker/Makefile.am new file mode 100644 index 0000000..8c86635 --- /dev/null +++ b/kicker-applets/kolourpicker/Makefile.am @@ -0,0 +1,23 @@ + +INCLUDES = $(all_includes) + +kde_module_LTLIBRARIES = kolourpicker_panelapplet.la + +kolourpicker_panelapplet_la_SOURCES = kolourpicker.cpp simplebutton.cpp + +noinst_HEADERS = kolourpicker.h + +kolourpicker_panelapplet_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) +kolourpicker_panelapplet_la_LIBADD = $(LIB_KDEUI) + +METASOURCES = AUTO + +lnkdir = $(kde_datadir)/kicker/applets + +lnk_DATA = kolourpicker.desktop + +EXTRA_DIST = $(lnk_DATA) + +messages: rc.cpp + $(XGETTEXT) *.cpp *.h -o $(podir)/kolourpicker.pot + diff --git a/kicker-applets/kolourpicker/TODO b/kicker-applets/kolourpicker/TODO new file mode 100644 index 0000000..44d9566 --- /dev/null +++ b/kicker-applets/kolourpicker/TODO @@ -0,0 +1 @@ +Add a menu item to edit the colour via KColorDialog (wish by Neil Stevens <[email protected]>) diff --git a/kicker-applets/kolourpicker/kolourpicker.cpp b/kicker-applets/kolourpicker/kolourpicker.cpp new file mode 100644 index 0000000..98f5302 --- /dev/null +++ b/kicker-applets/kolourpicker/kolourpicker.cpp @@ -0,0 +1,382 @@ +/* This file is part of KolourPicker + Copyright (c) 2001 Malte Starostik <[email protected]> + + 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; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + +$Id$ +*/ + +#include <qfile.h> +#include <qtextstream.h> +#include <qlayout.h> +#include <qimage.h> +#include <qclipboard.h> +#include <qregexp.h> +#include <qbitmap.h> +#include <qpainter.h> +#include <qtooltip.h> +#include <qcursor.h> + +#include <kglobal.h> +#include <klocale.h> +#include <kiconloader.h> +#include <kinstance.h> +#include <kconfig.h> +#include <kaboutdata.h> +#include <kaboutapplication.h> +#include <kmessagebox.h> +#include <kpopupmenu.h> + +#include "kolourpicker.h" +#include "kolourpicker.moc" + +#include <X11/Xlib.h> + +// Applet initialization function +extern "C" +{ + KDE_EXPORT KPanelApplet* init(QWidget *parent, const QString& configFile) + { + KGlobal::locale()->insertCatalogue("kolourpicker"); + return new KolourPicker(configFile, KPanelApplet::Normal, + KPanelApplet::About, + parent, "kolourpicker"); + } +} + +KolourPicker::KolourPicker(const QString& configFile, Type type, + int actions, QWidget *parent, const char *name) + : KPanelApplet(configFile, type, actions, parent, name), + m_picking(0) +{ + KAboutData *about = new KAboutData("kolourpicker", + I18N_NOOP("Color Picker"), + "v0.1", + I18N_NOOP("An applet to pick color values from anywhere on the screen"), + KAboutData::License_GPL_V2, + "(c) 2001 Malte Starostik"); + about->addAuthor("Malte Starostik", I18N_NOOP("Original Author"), "[email protected]"); + m_instance = new KInstance(about); + + KConfig *conf = config(); + conf->setGroup("General"); + QStringList history = conf->readListEntry("History"); + for (QStringList::ConstIterator it = history.begin(); it != history.end(); ++it) + m_history.append(QColor(*it)); + + setBackgroundOrigin(AncestorOrigin); + + m_colourButton = new SimpleButton(this); + m_colourButton->setPixmap(SmallIcon("colorpicker")); + m_colourButton->setFixedSize(20, 20); + QToolTip::add(m_colourButton, i18n("Pick a color")); + connect(m_colourButton, SIGNAL(clicked()), SLOT(slotPick())); + + m_historyButton = new SimpleButton(this); + m_historyButton->setFixedSize(20, 20); + if (m_history.count()) + m_historyButton->setPixmap(colorPixmap(m_history.last())); + else + { + m_historyButton->setPixmap(colorPixmap(QColor())); + m_historyButton->setEnabled(false); + } + QToolTip::add(m_historyButton, i18n("History")); + connect(m_historyButton, SIGNAL(clicked()), SLOT(slotHistory())); +} + +KolourPicker::~KolourPicker() +{ + KGlobal::locale()->removeCatalogue("kolourpicker"); +} + + +int KolourPicker::heightForWidth(int width) const +{ + return (width > 40) ? 22 : 44; +} + +int KolourPicker::widthForHeight(int height) const +{ + return (height > 40) ? 22 : 44; +} + +void KolourPicker::about() +{ + KAboutApplication dlg(m_instance->aboutData()); + dlg.exec(); +} + +void KolourPicker::slotPick() +{ + m_picking = true; + grabMouse(crossCursor); + grabKeyboard(); +} + +void KolourPicker::slotHistory() +{ + KPopupMenu popup; + popup.insertTitle(SmallIcon("colorize"), i18n("History")); + QPtrList<QPopupMenu> subMenus; + subMenus.setAutoDelete(true); + for (QValueList<QColor>::ConstIterator it = m_history.fromLast(); + it != m_history.end(); + --it) + { + QPopupMenu *sub = copyPopup(*it, false); + subMenus.append(sub); + popup.insertItem(colorPixmap(*it), + QString("%1, %2, %3").arg((*it).red()).arg((*it).green()).arg((*it).blue()), + sub); + } + popup.insertSeparator(); + int clear = popup.insertItem(SmallIcon("history_clear"), i18n("&Clear History")); + int id = popup.exec(QCursor::pos()); + if (id == clear) + { + m_history.clear(); + m_historyButton->setEnabled(false); + arrangeButtons(); + KConfig *conf = config(); + conf->setGroup("General"); + conf->writeEntry("History", QStringList()); + conf->sync(); + } + else if (id != -1) + setClipboard(popup.findItem(id)->text()); +} + +void KolourPicker::mouseReleaseEvent(QMouseEvent *e) +{ + if (m_picking) + { + m_picking = false; + releaseMouse(); + releaseKeyboard(); + QWidget *desktop = QApplication::desktop(); + QPixmap pm = QPixmap::grabWindow(desktop->winId(), + e->globalPos().x(), e->globalPos().y(), 1, 1); + QImage img = pm.convertToImage(); + QColor color(img.pixel(0, 0)); + + // eventually remove a dupe + QValueListIterator<QColor> dupe = m_history.find(color); + if (dupe != m_history.end()) + m_history.remove(dupe); + + m_history.append(color); + while (m_history.count() >= 10) + m_history.remove(m_history.begin()); + m_historyButton->setEnabled(true); + arrangeButtons(); + QStringList history; + for (QValueList<QColor>::ConstIterator it = m_history.begin(); + it != m_history.end(); + ++it) + { + history.append((*it).name()); + } + KConfig *conf = config(); + conf->setGroup("General"); + conf->writeEntry("History", history); + conf->sync(); + m_historyButton->setPixmap(colorPixmap(color)); + QPopupMenu *popup = copyPopup(color, true); + int id = popup->exec(e->globalPos()); + if (id != -1) + setClipboard( popup->findItem(id)->text() ); + delete popup; + } + else + KPanelApplet::mouseReleaseEvent(e); +} + +// set both clipboard and selection +void KolourPicker::setClipboard(const QString& text) +{ + QClipboard *clip = QApplication::clipboard(); + bool oldMode = clip->selectionModeEnabled(); + clip->setSelectionMode(true); + clip->setText(text); + clip->setSelectionMode(false); + clip->setText(text); + clip->setSelectionMode( oldMode ); +} + +void KolourPicker::keyPressEvent(QKeyEvent *e) +{ + if (m_picking) + { + if (e->key() == Key_Escape) + { + m_picking = false; + releaseMouse(); + releaseKeyboard(); + } + e->accept(); + return; + } + KPanelApplet::keyPressEvent(e); +} + +void KolourPicker::resizeEvent(QResizeEvent *) +{ + arrangeButtons(); +} + +void KolourPicker::arrangeButtons() +{ + int h, w, p; + + if (orientation() == Horizontal) + { + h = height(); + if (h > 40) + { + // vertical layout + p = (h - 40)/3; + m_colourButton->setGeometry(2, p, 20, 20); + m_historyButton->setGeometry(2, 2*p+20, 20, 20); + } + else + { + // horizontal layout + p = (h - 20)/2; + m_colourButton->setGeometry(2, p, 20, 20); + m_historyButton->setGeometry(24, p, 20, 20); + } + } + else + { + w = width(); + if (w > 40) + { + // horizontal layout + p = (w - 40)/3; + m_colourButton->setGeometry(p, 2, 20, 20); + m_historyButton->setGeometry(2*p+20, 2, 20, 20); + } + else + { + // vertical layout + p = (w - 20)/2; + m_colourButton->setGeometry(p, 2, 20, 20); + m_historyButton->setGeometry(p, 24, 20, 20); + } + } + + updateGeometry(); +} + +QPopupMenu *KolourPicker::copyPopup(const QColor &c, bool title) const +{ + KPopupMenu *popup = new KPopupMenu; + if (title) + popup->insertTitle(colorPixmap(c), i18n("Copy Color Value")); + QString value; + // r, g, b + value.sprintf("%u, %u, %u", c.red(), c.green(), c.blue()); + popup->insertItem(SmallIcon("text"), value); + // HTML, lower case hex chars + value.sprintf("#%.2x%.2x%.2x", c.red(), c.green(), c.blue()); + popup->insertItem(SmallIcon("html"), value); + if (value.find(QRegExp("[a-f]")) >= 0) + { + // HTML, upper case hex chars + value.sprintf("#%.2X%.2X%.2X", c.red(), c.green(), c.blue()); + popup->insertItem(SmallIcon("html"), value); + } + // lower case hex chars + value.sprintf( "%.2x%.2x%.2x", c.red(), c.green(), c.blue() ); + popup->insertItem( SmallIcon( "html" ), value ); + if ( value.find( QRegExp( "[a-f]" ) ) >= 0 ) + { + // upper case hex chars + value.sprintf( "%.2X%.2X%.2X", c.red(), c.green(), c.blue() ); + popup->insertItem( SmallIcon( "html" ), value ); + } + // Color name + QStringList names = colorNames(c.red(), c.green(), c.blue()); + for (QStringList::ConstIterator it = names.begin(); it != names.end(); ++it) + popup->insertItem(SmallIcon("text"), *it); + return popup; +} + +#define AAFACTOR 4 + +QPixmap KolourPicker::colorPixmap(const QColor &c) const +{ + int x, y, dx, dy, d; + + QImage img(16 * AAFACTOR, 16 * AAFACTOR, 32); + img.setAlphaBuffer(true); + img.fill(0); + + for (x = 0; x < img.width(); x++) + for (y = 0; y < img.height(); y++) + { + dx = 1 + x - 15 * AAFACTOR / 2; + dy = 1 + y - 15 * AAFACTOR / 2; + d = dx * dx + dy * dy; + + if (d < (36 * AAFACTOR * AAFACTOR)) + img.setPixel(x, y, c.pixel()); + else if (d < (56.25 * AAFACTOR * AAFACTOR)) + img.setPixel(x, y, qRgba(128, 128, 128, 255)); + } + + QBitmap mask(16, 16); + mask.fill(Qt::color0); + QPainter p(&mask); + p.setPen(Qt::NoPen); + p.setBrush(Qt::color1); + p.drawEllipse(0, 0, 15, 15); + p.end(); + + QPixmap pm = QPixmap(img.smoothScale(16, 16)); + pm.setMask(mask); + + return pm; +} + +const QStringList &KolourPicker::colorNames(int r, int g, int b) const +{ + static QStringList NullList; + if (m_colorNames.isEmpty()) + { + QFile f("/usr/lib/X11/rgb.txt"); + if (!f.open(IO_ReadOnly)) + return NullList; + QTextStream str(&f); + QString red, green, blue; + while (!str.atEnd()) + { + str >> red; + if (red.simplifyWhiteSpace()[0].latin1() == '!') + { + str.readLine(); + continue; + } + str >> green >> blue; + const_cast<KolourPicker *>(this)->m_colorNames[(red.toInt() << 16) + (green.toInt() << 8) + blue.toInt()] + .append(str.readLine().simplifyWhiteSpace()); + } + } + return m_colorNames[(r << 16) + (g << 8) + b]; +} + +// vim: ts=4 sw=4 noet diff --git a/kicker-applets/kolourpicker/kolourpicker.desktop b/kicker-applets/kolourpicker/kolourpicker.desktop new file mode 100644 index 0000000..34f13d0 --- /dev/null +++ b/kicker-applets/kolourpicker/kolourpicker.desktop @@ -0,0 +1,145 @@ +[Desktop Entry] +Type=Plugin +Name=Color Picker +Name[af]=Kleur Kieser +Name[ar]=أداة اختيار الألوان +Name[az]=Rəng Alıcısı +Name[bg]=Избор на цвят +Name[br]=Dibaber al liv +Name[bs]=Izbornik boja +Name[ca]=Selector de colors +Name[cs]=Výběr barev +Name[cy]=Dewisydd Lliw +Name[da]=Farveplukker +Name[de]=Farbauswahl +Name[el]=Επιλογή χρωμάτων +Name[en_GB]=Colour Picker +Name[eo]=Kolorelektilo +Name[es]=Selector de color +Name[et]=Värvide valimine +Name[eu]=Kolore hautagailua +Name[fa]=برگزینندۀ رنگ +Name[fi]=Värivalitsin +Name[fo]=Litveljari +Name[fr]=Pipette +Name[fy]=Kleurekiezer +Name[gl]=Escolla de Cores +Name[he]=בוחר צבעים +Name[hi]=रंग चयनक +Name[hr]=Birač boja +Name[hu]=Színválasztó +Name[is]=Litaval +Name[it]=Scelta colore +Name[ja]=色の抽出 +Name[ka]=ფერთა ამღები +Name[kk]=Түсті шұқып алу +Name[km]=កម្មវិធីរើសពណ៌ +Name[ko]=색 고르기 +Name[lt]=Spalvų rinkėjas +Name[lv]=Krāsu Lasītājs +Name[mk]=Бирач на бои +Name[ms]=Pengutip Warna +Name[mt]=Agħżel kulur +Name[nb]=Fargevelger +Name[nds]=Klöörutwahl +Name[ne]=रङ पिकर +Name[nl]=Kleurenkiezer +Name[nn]=Fargeveljar +Name[pa]=ਰੰਗ ਚੋਣਕਾਰ +Name[pl]=Wybór koloru +Name[pt]=Escolha de Cores +Name[pt_BR]=Seletor de cores +Name[ro]=Selector de culori +Name[ru]=Выбор цвета +Name[sk]=Výber farieb +Name[sl]=Izbirnik barv +Name[sr]=Бирач боја +Name[sr@Latn]=Birač boja +Name[sv]=Färgväljare +Name[ta]=வண்ண எடுப்பான் +Name[tg]=Интихоби рангҳо +Name[th]=เครื่องมือเลือกสี +Name[tr]=Renk Seçici +Name[uk]=Селектор кольорів +Name[uz]=Rang tanlagich +Name[uz@cyrillic]=Ранг танлагич +Name[ven]=Tshidobamuvhala +Name[vi]=Bộ kén màu +Name[xh]=Umkhethi Wombala +Name[zh_CN]=颜色提取程序 +Name[zh_TW]=色彩選擇器 +Name[zu]=Umcoshi Wombala +Icon=colorpicker +Comment=Pick colors from anywhere and get their values +Comment[af]=Kies kleure van orals en kry hulle waardes +Comment[ar]=اختر الألوان من أي مكان و احصل على قيمتها الرقمية +Comment[az]=İstədiyiniz yerdən rəng alaraq qiymətlərini öyrənin +Comment[bg]=Избор на цвят от екрана и получаване на неговата стойност +Comment[bs]=Izbor boje sa bilo kojeg mjesta i ispis njenih vrijednosti +Comment[ca]=Selecciona colors des de qualsevol lloc i obté els seus valors +Comment[cs]=Výběr barev z libovolného místa a získání jejich hodnot +Comment[cy]=Dewis lliwiau oddiwrth unrhyw man a cael eu gwerthoedd +Comment[da]=Pluk farver fra et vilkårligt sted og få deres værdier +Comment[de]=Farben aufnehmen und ihre RGB-Werte ermitteln +Comment[el]=Επιλέξτε χρώματα από οπουδήποτε και πάρτε τις τιμές τους +Comment[en_GB]=Pick colours from anywhere and get their values +Comment[eo]=Elprenas koloron de ie sur la ekrano kaj montras ĝiajn valorojn +Comment[es]=Selecciona colores desde cualquier sitio y devuelve sus valores +Comment[et]=Värvide valimine ekraanilt ja nende väärtuste vaatamine +Comment[eu]=Hautatu koloreak edonondik eta euren balioak eskuratu +Comment[fa]=رنگها را از هر جایی برگزیده و مقادیر آنها را به دست میآورد. +Comment[fi]=Valitse värejä kaikkialta ja tutki värien arvoja +Comment[fo]=Vel litir frá skriviborði. +Comment[fr]=Capture une couleur n'importe où et obtient sa composition +Comment[fy]=Kies kleuren fan elk willekeurich plak en krij harren wearden +Comment[ga]=Roghnaigh dath ó áit ar bith agus faigh a luach +Comment[gl]=Extrai as cores de calquer sítio e obtén os seus valores +Comment[he]=בחירת צבעים מכל מקום שהוא וקבלת ערכיהם +Comment[hi]=कहीं से भी रंग चुने तथा उसका मान प्रदर्शित करता है +Comment[hr]=Odabir boja s bilo kojeg mjesta i iščitavanje njihovih vrijednosti +Comment[hu]=Színleolvasás a képernyő bármely képpontjáról +Comment[is]=Velja liti hvaðan sem er af skjánum og fá tölugildi þeirra +Comment[it]=Scegli un colore da un posto qualsiasi e scopri il suo valore +Comment[ja]=色を抽出してそれの値を読み込みます +Comment[ka]=ნებისმიერი ადგილიდან იღებს ფერს, მათი მნიშვნელობის მისაღებად +Comment[kk]=Кез келген жерден түсті шұқып, параметрлерін алу +Comment[km]=រើសពណ៌ពីកន្លែងណាមួយ និងយកតម្លៃរបស់ពួកវា +Comment[ko]=어디에 있는 색이든 고를 수 있는 도구 +Comment[lt]=Paima iš bet kur spalvas ir parodo jų reikšmes +Comment[lv]= Lasa krāsas no jebkurienes un iegūst to vērtības +Comment[mk]=Избира бои од каде било и ги зема нивните вредности +Comment[ms]=Memungut warna dari mana-mana dan dapatkan nilainya +Comment[mt]=Agħżel kulur minn fejn trid u ħu l-valur tiegħu +Comment[nb]=Plukk opp farger fra hvor som helst og se verdiene deres +Comment[nds]=Klören jichtenswo utsöken un ehr Weerten faststellen +Comment[ne]=सबै ठाउको रङ लिनुहोस् र तिनका मान प्राप्त गर्नुहोस् +Comment[nl]=Kies kleuren van elke willekeurige plek en verkrijg hun waarden +Comment[nn]=Plukk fargar frå kvar som helst og finn verdien deira +Comment[pa]=ਕਿਤੋਂ ਵੀ ਰੰਗ ਵੀ ਚੁੱਕੋ ਅਤੇ ਉਹਨਾਂ ਦੇ ਮੁੱਲ ਲਵੋ +Comment[pl]=Wybierz kolory z dowolnego miejsca i pobierz ich wartości +Comment[pt]=Extrai as cores de qualquer sítio e obtém os seus valores +Comment[pt_BR]=Selecione as cores de qualquer lugar e obtenha seus valores +Comment[ro]=Preia culori de oriunde şi afişează valorile lor +Comment[ru]=Подбирает цвет из любого места экрана и показывает его значение +Comment[sk]=Výber farieb z ktoréhokoľvek miesta a získanie ich hodnôt +Comment[sl]=Pobira barve od vsepovsod in dobiva njihove vrednosti +Comment[sr]=Узмите узорак боје одакле било и сазнајте њену вредност +Comment[sr@Latn]=Uzmite uzorak boje odakle bilo i saznajte njenu vrednost +Comment[sv]=Välj färger var som helst och få deras värden +Comment[ta]=எங்கிருந்தும் வண்ணங்களைத் எடுத்து அதன் மதிப்புகளை பெறு +Comment[tg]=Интихоб кардани ранг аз ҳар ҷойи экран ва нишон додани қимати ӯ +Comment[th]=เลือกสีจากที่ใด ๆ และรับค่าของมัน +Comment[tr]=Herhangi bir yerden renk seçer ve değerlerini alır +Comment[uk]=Вибирає кольори будь-звідки та отримує їхні значення +Comment[uz]=Ekranning istalgan joyidan rang va uning qiymatini olish +Comment[uz@cyrillic]=Экраннинг исталган жойидан ранг ва унинг қийматини олиш +Comment[ven]=Zwi doba mivhala hothe na hothe zwa wana kuitele kwazwo +Comment[vi]=Kén màu từ bất cứ nơi nào và lấy giá trị của nó +Comment[xh]=Khetha imibala esuka naphi na ze ufumane amaxabiso awo +Comment[zh_CN]=从任何地方获取颜色值 +Comment[zh_TW]=從點選的地方取得顏色值 +Comment[zu]=Cosha imibala kunoma ikephi kanye namabizo azo ufumane amaxabiso ayo +X-KDE-Library=kolourpicker_panelapplet +X-KDE-UniqueApplet=true +DocPath=kicker-applets/kolourpicker.html +X-KDE-ParentApp=applets diff --git a/kicker-applets/kolourpicker/kolourpicker.h b/kicker-applets/kolourpicker/kolourpicker.h new file mode 100644 index 0000000..0b576e9 --- /dev/null +++ b/kicker-applets/kolourpicker/kolourpicker.h @@ -0,0 +1,70 @@ +/* This file is part of Kolourpicker + Copyright (c) 2001 Malte Starostik <[email protected]> + + 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; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + +*/ + +#ifndef _KOLOURPICKER_H_ +#define _KOLOURPICKER_H_ + +#include <qmap.h> +#include <qvaluelist.h> + +#include <kpanelapplet.h> + +#include "simplebutton.h" + +class KInstance; +class QPopupMenu; + +class KolourPicker : public KPanelApplet +{ + Q_OBJECT +public: + KolourPicker(const QString& configFile, Type t = Normal, int actions = 0, + QWidget *parent = 0, const char *name = 0); + ~KolourPicker(); + virtual int heightForWidth(int) const; + virtual int widthForHeight(int) const; + virtual void about(); + +protected: + virtual void mouseReleaseEvent(QMouseEvent *); + virtual void keyPressEvent(QKeyEvent *); + virtual void resizeEvent(QResizeEvent*); + +private slots: + void slotPick(); + void slotHistory(); + +private: + QPopupMenu *copyPopup(const QColor &, bool title) const; + QPixmap colorPixmap(const QColor &) const; + const QStringList &colorNames(int r, int g, int b) const; + void arrangeButtons(); + void setClipboard(const QString& text); + + KInstance *m_instance; + bool m_picking; + SimpleButton *m_historyButton, *m_colourButton; + QValueList<QColor> m_history; + QMap<int, QStringList> m_colorNames; +}; + +#endif + +// vim: ts=4 sw=4 noet diff --git a/kicker-applets/kolourpicker/simplebutton.cpp b/kicker-applets/kolourpicker/simplebutton.cpp new file mode 100644 index 0000000..9daa926 --- /dev/null +++ b/kicker-applets/kolourpicker/simplebutton.cpp @@ -0,0 +1,256 @@ +/* This file is part of the KDE project + Copyright (C) 2003-2004 Nadeem Hasan <[email protected]> + Copyright (C) 2004-2005 Aaron J. Seigo <[email protected]> + + 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; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "simplebutton.h" + +#include <qpainter.h> +#include <qstyle.h> + +#include <kapplication.h> +#include <kcursor.h> +#include <kdialog.h> +#include <kglobalsettings.h> +#include <kiconeffect.h> +#include <kicontheme.h> +#include <kipc.h> +#include <kstandarddirs.h> + +SimpleButton::SimpleButton(QWidget *parent, const char *name) + : QButton(parent, name), + m_highlight(false), + m_orientation(Qt::Horizontal) +{ + setBackgroundOrigin( AncestorOrigin ); + + connect( kapp, SIGNAL( settingsChanged( int ) ), + SLOT( slotSettingsChanged( int ) ) ); + connect( kapp, SIGNAL( iconChanged( int ) ), + SLOT( slotIconChanged( int ) ) ); + + kapp->addKipcEventMask( KIPC::SettingsChanged ); + kapp->addKipcEventMask( KIPC::IconChanged ); + + slotSettingsChanged( KApplication::SETTINGS_MOUSE ); +} + +void SimpleButton::setPixmap(const QPixmap &pix) +{ + QButton::setPixmap(pix); + generateIcons(); + update(); +} + +void SimpleButton::setOrientation(Qt::Orientation orientation) +{ + m_orientation = orientation; + update(); +} + +QSize SimpleButton::sizeHint() const +{ + const QPixmap* pm = pixmap(); + + if (!pm) + return QButton::sizeHint(); + else + return QSize(pm->width() + KDialog::spacingHint(), pm->height() + KDialog::spacingHint()); +} + +QSize SimpleButton::minimumSizeHint() const +{ + const QPixmap* pm = pixmap(); + + if (!pm) + return QButton::minimumSizeHint(); + else + return QSize(pm->width(), pm->height()); +} + +void SimpleButton::drawButton( QPainter *p ) +{ + drawButtonLabel(p); +} + +void SimpleButton::drawButtonLabel( QPainter *p ) +{ + if (!pixmap()) + { + return; + } + + QPixmap pix = isEnabled() ? (m_highlight? m_activeIcon : m_normalIcon) : m_disabledIcon; + + if (isOn() || isDown()) + { + pix = pix.convertToImage().smoothScale(pix.width() - 2, + pix.height() - 2); + } + + int h = height(); + int w = width(); + int ph = pix.height(); + int pw = pix.width(); + int margin = KDialog::spacingHint(); + QPoint origin(margin / 2, margin / 2); + + if (ph < (h - margin)) + { + origin.setY((h - ph) / 2); + } + + if (pw < (w - margin)) + { + origin.setX((w - pw) / 2); + } + + p->drawPixmap(origin, pix); +} + +void SimpleButton::generateIcons() +{ + if (!pixmap()) + { + return; + } + + QImage image = pixmap()->convertToImage(); + KIconEffect effect; + + m_normalIcon = effect.apply(image, KIcon::Panel, KIcon::DefaultState); + m_activeIcon = effect.apply(image, KIcon::Panel, KIcon::ActiveState); + m_disabledIcon = effect.apply(image, KIcon::Panel, KIcon::DisabledState); + + updateGeometry(); +} + +void SimpleButton::slotSettingsChanged(int category) +{ + if (category != KApplication::SETTINGS_MOUSE) + { + return; + } + + bool changeCursor = KGlobalSettings::changeCursorOverIcon(); + + if (changeCursor) + { + setCursor(KCursor::handCursor()); + } + else + { + unsetCursor(); + } +} + +void SimpleButton::slotIconChanged( int group ) +{ + if (group != KIcon::Panel) + { + return; + } + + generateIcons(); + update(); +} + +void SimpleButton::enterEvent( QEvent *e ) +{ + m_highlight = true; + + repaint( false ); + QButton::enterEvent( e ); +} + +void SimpleButton::leaveEvent( QEvent *e ) +{ + m_highlight = false; + + repaint( false ); + QButton::enterEvent( e ); +} + +void SimpleButton::resizeEvent( QResizeEvent * ) +{ + generateIcons(); +} + + +SimpleArrowButton::SimpleArrowButton(QWidget *parent, Qt::ArrowType arrow, const char *name) + : SimpleButton(parent, name) +{ + setBackgroundOrigin(AncestorOrigin); + _arrow = arrow; + _inside = false; +} + +QSize SimpleArrowButton::sizeHint() const +{ + return QSize( 12, 12 ); +} + +void SimpleArrowButton::setArrowType(Qt::ArrowType a) +{ + if (_arrow != a) + { + _arrow = a; + update(); + } +} + +Qt::ArrowType SimpleArrowButton::arrowType() const +{ + return _arrow; +} + +void SimpleArrowButton::drawButton( QPainter *p ) +{ + QRect r(1, 1, width() - 2, height() - 2); + + QStyle::PrimitiveElement pe = QStyle::PE_ArrowLeft; + switch (_arrow) + { + case Qt::LeftArrow: pe = QStyle::PE_ArrowLeft; break; + case Qt::RightArrow: pe = QStyle::PE_ArrowRight; break; + case Qt::UpArrow: pe = QStyle::PE_ArrowUp; break; + case Qt::DownArrow: pe = QStyle::PE_ArrowDown; break; + } + + int flags = QStyle::Style_Default | QStyle::Style_Enabled; + if (isDown() || isOn()) flags |= QStyle::Style_Down; + style().drawPrimitive(pe, p, r, colorGroup(), flags); +} + +void SimpleArrowButton::enterEvent( QEvent *e ) +{ + _inside = true; + SimpleButton::enterEvent( e ); + update(); +} + +void SimpleArrowButton::leaveEvent( QEvent *e ) +{ + _inside = false; + SimpleButton::enterEvent( e ); + update(); +} + +#include "simplebutton.moc" + +// vim:ts=4:sw=4:et diff --git a/kicker-applets/kolourpicker/simplebutton.h b/kicker-applets/kolourpicker/simplebutton.h new file mode 100644 index 0000000..5423dff --- /dev/null +++ b/kicker-applets/kolourpicker/simplebutton.h @@ -0,0 +1,89 @@ +/* This file is part of the KDE project + Copyright (C) 2003-2004 Nadeem Hasan <[email protected]> + Copyright (C) 2004-2005 Aaron J. Seigo <[email protected]> + + 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; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SIMPLEBUTTON_H +#define SIMPLEBUTTON_H + +#include <qbutton.h> +#include <qpixmap.h> + +#include <kdemacros.h> + +class KDE_EXPORT SimpleButton : public QButton +{ + Q_OBJECT + + public: + SimpleButton(QWidget *parent, const char *name = 0); + void setPixmap(const QPixmap &pix); + void setOrientation(Qt::Orientation orientaton); + QSize sizeHint() const; + QSize minimumSizeHint() const; + + protected: + void drawButton( QPainter *p ); + void drawButtonLabel( QPainter *p ); + void generateIcons(); + + void enterEvent( QEvent *e ); + void leaveEvent( QEvent *e ); + void resizeEvent( QResizeEvent *e ); + + protected slots: + virtual void slotSettingsChanged( int category ); + virtual void slotIconChanged( int group ); + + private: + bool m_highlight; + QPixmap m_normalIcon; + QPixmap m_activeIcon; + QPixmap m_disabledIcon; + Qt::Orientation m_orientation; + class SimpleButtonPrivate; + SimpleButtonPrivate* d; +}; + +class KDE_EXPORT SimpleArrowButton: public SimpleButton +{ + Q_OBJECT + + public: + SimpleArrowButton(QWidget *parent = 0, Qt::ArrowType arrow = Qt::UpArrow, const char *name = 0); + virtual ~SimpleArrowButton() {}; + QSize sizeHint() const; + + protected: + virtual void enterEvent( QEvent *e ); + virtual void leaveEvent( QEvent *e ); + virtual void drawButton(QPainter *p); + Qt::ArrowType arrowType() const; + + public slots: + void setArrowType(Qt::ArrowType a); + + private: + Qt::ArrowType _arrow; + bool _inside; +}; + + +#endif // HIDEBUTTON_H + +// vim:ts=4:sw=4:et |