summaryrefslogtreecommitdiffstats
path: root/chalk/ui/kis_palette_view.cc
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-26 00:41:16 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-26 00:41:16 +0000
commit698569f8428ca088f764d704034a1330517b98c0 (patch)
treebf45be6946ebbbee9cce5a5bcf838f4c952d87e6 /chalk/ui/kis_palette_view.cc
parent2785103a6bd4de55bd26d79e34d0fdd4b329a73a (diff)
downloadkoffice-698569f8428ca088f764d704034a1330517b98c0.tar.gz
koffice-698569f8428ca088f764d704034a1330517b98c0.zip
Finish rebranding of Krita as Chalk
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1238363 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'chalk/ui/kis_palette_view.cc')
-rw-r--r--chalk/ui/kis_palette_view.cc150
1 files changed, 150 insertions, 0 deletions
diff --git a/chalk/ui/kis_palette_view.cc b/chalk/ui/kis_palette_view.cc
new file mode 100644
index 00000000..dfc75eb4
--- /dev/null
+++ b/chalk/ui/kis_palette_view.cc
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2005 Boudewijn Rempt <[email protected]>
+ * (c) 2005 Bart Coppens <[email protected]>
+ *
+ * Based on already much changed code by Waldo Bastian <[email protected]> from KisPaletteWidget
+ *
+ * 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <tqcheckbox.h>
+#include <tqcombobox.h>
+#include <tqdrawutil.h>
+#include <tqevent.h>
+#include <tqfile.h>
+#include <tqimage.h>
+#include <tqlabel.h>
+#include <tqlayout.h>
+#include <tqlineedit.h>
+#include <tqvalidator.h>
+#include <tqpainter.h>
+#include <tqpushbutton.h>
+#include <tqspinbox.h>
+#include <tqtimer.h>
+
+#include <kapplication.h>
+#include <kconfig.h>
+#include <kglobal.h>
+#include <kglobalsettings.h>
+#include <kiconloader.h>
+#include <klistbox.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kseparator.h>
+#include <kpalette.h>
+#include <kimageeffect.h>
+
+#include <kcolordialog.h>
+#include <kcolordrag.h>
+#include <config.h>
+#include <kdebug.h>
+
+#include <kis_meta_registry.h>
+#include <kis_color.h>
+#include <kis_factory.h>
+#include <kis_colorspace_factory_registry.h>
+#include "kis_palette_view.h"
+#include "kis_resource.h"
+#include "kis_palette.h"
+
+KisPaletteView::KisPaletteView(TQWidget *tqparent, const char* name, int minWidth, int cols)
+ : TQScrollView( tqparent, name ), mMinWidth(minWidth), mCols(cols)
+{
+ m_cells = 0;
+ m_currentPalette = 0;
+
+ TQSize cellSize = TQSize( mMinWidth, 50);
+
+ setHScrollBarMode(TQScrollView::AlwaysOff);
+ setVScrollBarMode(TQScrollView::AlwaysOn);
+
+ TQSize minSize = TQSize(verticalScrollBar()->width(), 0);
+ minSize += TQSize(frameWidth(), 0);
+ minSize += TQSize(cellSize);
+
+ setMinimumSize(minSize);
+ tqsetSizePolicy(TQSizePolicy(TQSizePolicy::Ignored, TQSizePolicy::Ignored));
+}
+
+KisPaletteView::~KisPaletteView()
+{
+}
+
+KisPalette* KisPaletteView::palette() const
+{
+ return m_currentPalette;
+}
+
+void KisPaletteView::setPalette(KisPalette* palette)
+{
+ m_currentPalette = palette;
+ delete m_cells;
+
+ int rows = (m_currentPalette->nColors() + mCols -1 ) / mCols;
+
+ if (rows < 1) rows = 1;
+
+ m_cells = new KColorCells(viewport(), rows, mCols);
+ Q_CHECK_PTR(m_cells);
+
+ m_cells->setShading(false);
+ m_cells->setAcceptDrags(false);
+
+ TQSize cellSize = TQSize( mMinWidth, mMinWidth * rows / mCols);
+ m_cells->setFixedSize( cellSize );
+
+ for( int i = 0; i < m_currentPalette->nColors(); i++)
+ {
+ TQColor c = m_currentPalette->getColor(i).color;
+ m_cells->setColor( i, c );
+ }
+
+ connect(m_cells, TQT_SIGNAL(colorSelected(int)),
+ TQT_SLOT(slotColorCellSelected(int)));
+
+ connect(m_cells, TQT_SIGNAL(colorDoubleClicked(int)),
+ TQT_SLOT(slotColorCellDoubleClicked(int)) );
+
+ addChild( m_cells );
+ m_cells->show();
+ updateScrollBars();
+}
+
+void KisPaletteView::slotColorCellSelected( int col )
+{
+ KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getRGB8();
+ if (!m_currentPalette || (col >= m_currentPalette->nColors()))
+ return;
+
+ m_currentEntry = m_currentPalette->getColor(col);
+ emit colorSelected(KisColor(m_currentPalette->getColor(col).color, cs));
+ emit colorSelected(m_currentPalette->getColor(col).color);
+}
+
+void KisPaletteView::slotColorCellDoubleClicked( int col )
+{
+ KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getRGB8();
+ if (!m_currentPalette || (col >= m_currentPalette->nColors()))
+ return;
+
+ emit colorDoubleClicked(KisColor(m_currentPalette->getColor(col).color, cs),
+ m_currentPalette->getColor(col).name);
+}
+
+#include "kis_palette_view.moc"
+