diff --git a/libs/ui/KisNodeView.cpp b/libs/ui/KisNodeView.cpp index 98102d9bc2..b15fca7e12 100644 --- a/libs/ui/KisNodeView.cpp +++ b/libs/ui/KisNodeView.cpp @@ -1,564 +1,564 @@ /* Copyright (c) 2006 Gábor Lehel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "KisNodeView.h" #include "KisNodePropertyAction_p.h" #include "KisNodeDelegate.h" #include "kis_node_view_visibility_delegate.h" #include "kis_node_model.h" #include "kis_signals_blocker.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kis_node_view_color_scheme.h" #ifdef HAVE_X11 #define DRAG_WHILE_DRAG_WORKAROUND #endif #ifdef DRAG_WHILE_DRAG_WORKAROUND #define DRAG_WHILE_DRAG_WORKAROUND_START() d->isDragging = true #define DRAG_WHILE_DRAG_WORKAROUND_STOP() d->isDragging = false #else #define DRAG_WHILE_DRAG_WORKAROUND_START() #define DRAG_WHILE_DRAG_WORKAROUND_STOP() #endif class Q_DECL_HIDDEN KisNodeView::Private { public: Private(KisNodeView* _q) : delegate(_q, _q) - , mode(DetailedMode) + , mode(DetailedMode) #ifdef DRAG_WHILE_DRAG_WORKAROUND , isDragging(false) #endif { KSharedConfigPtr config = KSharedConfig::openConfig(); KConfigGroup group = config->group("NodeView"); mode = (DisplayMode) group.readEntry("NodeViewMode", (int)MinimalMode); } KisNodeDelegate delegate; DisplayMode mode; QPersistentModelIndex hovered; QPoint lastPos; #ifdef DRAG_WHILE_DRAG_WORKAROUND bool isDragging; #endif }; KisNodeView::KisNodeView(QWidget *parent) : QTreeView(parent) , m_draggingFlag(false) , d(new Private(this)) { setItemDelegateForColumn(0, &d->delegate); setMouseTracking(true); setSelectionBehavior(SelectRows); setDefaultDropAction(Qt::MoveAction); setVerticalScrollMode(QAbstractItemView::ScrollPerItem); setSelectionMode(QAbstractItemView::ExtendedSelection); header()->hide(); setDragEnabled(true); setDragDropMode(QAbstractItemView::DragDrop); setAcceptDrops(true); setDropIndicatorShown(true); } KisNodeView::~KisNodeView() { delete d; } void KisNodeView::setDisplayMode(DisplayMode mode) { if (d->mode != mode) { d->mode = mode; KSharedConfigPtr config = KSharedConfig::openConfig(); KConfigGroup group = config->group("NodeView"); group.writeEntry("NodeViewMode", (int)mode); scheduleDelayedItemsLayout(); } } KisNodeView::DisplayMode KisNodeView::displayMode() const { return d->mode; } void KisNodeView::addPropertyActions(QMenu *menu, const QModelIndex &index) { KisBaseNode::PropertyList list = index.data(KisNodeModel::PropertiesRole).value(); for (int i = 0, n = list.count(); i < n; ++i) { if (list.at(i).isMutable) { PropertyAction *a = new PropertyAction(i, list.at(i), index, menu); connect(a, SIGNAL(toggled(bool, const QPersistentModelIndex&, int)), this, SLOT(slotActionToggled(bool, const QPersistentModelIndex&, int))); menu->addAction(a); } } } void KisNodeView::updateNode(const QModelIndex &index) { dataChanged(index, index); } QItemSelectionModel::SelectionFlags KisNodeView::selectionCommand(const QModelIndex &index, const QEvent *event) const { /** * Qt has a bug: when we Ctrl+click on an item, the item's * selections gets toggled on mouse *press*, whereas usually it is * done on mouse *release*. Therefore the user cannot do a * Ctrl+D&D with the default configuration. This code fixes the * problem by manually returning QItemSelectionModel::NoUpdate * flag when the user clicks on an item and returning * QItemSelectionModel::Toggle on release. */ if (event && (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease) && index.isValid()) { const QMouseEvent *mevent = static_cast(event); if (mevent->button() == Qt::RightButton && selectionModel()->selectedIndexes().contains(index)) { // Allow calling context menu for multiple layers return QItemSelectionModel::NoUpdate; } if (event->type() == QEvent::MouseButtonPress && (mevent->modifiers() & Qt::ControlModifier)) { return QItemSelectionModel::NoUpdate; } if (event->type() == QEvent::MouseButtonRelease && (mevent->modifiers() & Qt::ControlModifier)) { return QItemSelectionModel::Toggle; } } /** * Qt 5.6 has a bug: it reads global modifiers, not the ones * passed from event. So if you paste an item using Ctrl+V it'll * select multiple layers for you */ Qt::KeyboardModifiers globalModifiers = QApplication::keyboardModifiers(); if (!event && globalModifiers != Qt::NoModifier) { return QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows; } return QAbstractItemView::selectionCommand(index, event); } QRect KisNodeView::visualRect(const QModelIndex &index) const { QRect rc = QTreeView::visualRect(index); rc.setLeft(0); return rc; } QRect KisNodeView::originalVisualRect(const QModelIndex &index) const { return QTreeView::visualRect(index); } QModelIndex KisNodeView::indexAt(const QPoint &point) const { KisNodeViewColorScheme scm; QModelIndex index = QTreeView::indexAt(point); if (!index.isValid() && point.x() < scm.visibilityColumnWidth()) { index = QTreeView::indexAt(point + QPoint(scm.visibilityColumnWidth(), 0)); } return index; } bool KisNodeView::viewportEvent(QEvent *e) { if (model()) { switch(e->type()) { case QEvent::MouseButtonPress: { DRAG_WHILE_DRAG_WORKAROUND_STOP(); const QPoint pos = static_cast(e)->pos(); d->lastPos = pos; if (!indexAt(pos).isValid()) { return QTreeView::viewportEvent(e); } QModelIndex index = model()->buddy(indexAt(pos)); if (d->delegate.editorEvent(e, model(), optionForIndex(index), index)) { return true; } } break; case QEvent::Leave: { QEvent e(QEvent::Leave); d->delegate.editorEvent(&e, model(), optionForIndex(d->hovered), d->hovered); d->hovered = QModelIndex(); } break; case QEvent::MouseMove: { #ifdef DRAG_WHILE_DRAG_WORKAROUND if (d->isDragging) { return false; } #endif const QPoint pos = static_cast(e)->pos(); QModelIndex hovered = indexAt(pos); if (hovered != d->hovered) { if (d->hovered.isValid()) { QEvent e(QEvent::Leave); d->delegate.editorEvent(&e, model(), optionForIndex(d->hovered), d->hovered); } if (hovered.isValid()) { QEvent e(QEvent::Enter); d->delegate.editorEvent(&e, model(), optionForIndex(hovered), hovered); } d->hovered = hovered; } /* This is a workaround for a bug in QTreeView that immediately begins a dragging action when the mouse lands on the decoration/icon of a different index and moves 1 pixel or more */ Qt::MouseButtons buttons = static_cast(e)->buttons(); if ((Qt::LeftButton | Qt::MidButton) & buttons) { if ((pos - d->lastPos).manhattanLength() > qApp->startDragDistance()) { return QTreeView::viewportEvent(e); } return true; } } break; case QEvent::ToolTip: { const QPoint pos = static_cast(e)->pos(); if (!indexAt(pos).isValid()) { return QTreeView::viewportEvent(e); } QModelIndex index = model()->buddy(indexAt(pos)); return d->delegate.editorEvent(e, model(), optionForIndex(index), index); } break; case QEvent::Resize: { scheduleDelayedItemsLayout(); break; } default: break; } } return QTreeView::viewportEvent(e); } void KisNodeView::contextMenuEvent(QContextMenuEvent *e) { QTreeView::contextMenuEvent(e); QModelIndex i = indexAt(e->pos()); if (model()) i = model()->buddy(i); showContextMenu(e->globalPos(), i); } void KisNodeView::showContextMenu(const QPoint &globalPos, const QModelIndex &index) { emit contextMenuRequested(globalPos, index); } void KisNodeView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) { QTreeView::currentChanged(current, previous); if (current != previous) { Q_ASSERT(!current.isValid() || current.model() == model()); model()->setData(current, true, KisNodeModel::ActiveRole); } } void KisNodeView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &/*roles*/) { QTreeView::dataChanged(topLeft, bottomRight); for (int x = topLeft.row(); x <= bottomRight.row(); ++x) { for (int y = topLeft.column(); y <= bottomRight.column(); ++y) { QModelIndex index = topLeft.sibling(x, y); if (index.data(KisNodeModel::ActiveRole).toBool()) { if (currentIndex() != index) { setCurrentIndex(index); } return; } } } } void KisNodeView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { QTreeView::selectionChanged(selected, deselected); emit selectionChanged(selectedIndexes()); } void KisNodeView::slotActionToggled(bool on, const QPersistentModelIndex &index, int num) { KisBaseNode::PropertyList list = index.data(KisNodeModel::PropertiesRole).value(); list[num].state = on; const_cast(index.model())->setData(index, QVariant::fromValue(list), KisNodeModel::PropertiesRole); } QStyleOptionViewItem KisNodeView::optionForIndex(const QModelIndex &index) const { QStyleOptionViewItem option = viewOptions(); option.rect = visualRect(index); if (index == currentIndex()) option.state |= QStyle::State_HasFocus; return option; } void KisNodeView::startDrag(Qt::DropActions supportedActions) { DRAG_WHILE_DRAG_WORKAROUND_START(); if (displayMode() == KisNodeView::ThumbnailMode) { const QModelIndexList indexes = selectionModel()->selectedIndexes(); if (!indexes.isEmpty()) { QMimeData *data = model()->mimeData(indexes); if (!data) { return; } QDrag *drag = new QDrag(this); drag->setPixmap(createDragPixmap()); drag->setMimeData(data); //m_dragSource = this; drag->exec(supportedActions); } } else { QTreeView::startDrag(supportedActions); } } QPixmap KisNodeView::createDragPixmap() const { const QModelIndexList selectedIndexes = selectionModel()->selectedIndexes(); Q_ASSERT(!selectedIndexes.isEmpty()); const int itemCount = selectedIndexes.count(); // If more than one item is dragged, align the items inside a // rectangular grid. The maximum grid size is limited to 4 x 4 items. int xCount = 2; int size = 96; if (itemCount > 9) { xCount = 4; size = KisIconUtils::SizeLarge; } else if (itemCount > 4) { xCount = 3; size = KisIconUtils::SizeHuge; } else if (itemCount < xCount) { xCount = itemCount; } int yCount = itemCount / xCount; if (itemCount % xCount != 0) { ++yCount; } if (yCount > xCount) { yCount = xCount; } // Draw the selected items into the grid cells QPixmap dragPixmap(xCount * size + xCount - 1, yCount * size + yCount - 1); dragPixmap.fill(Qt::transparent); QPainter painter(&dragPixmap); int x = 0; int y = 0; Q_FOREACH (const QModelIndex &selectedIndex, selectedIndexes) { const QImage img = selectedIndex.data(int(KisNodeModel::BeginThumbnailRole) + size).value(); - painter.drawPixmap(x, y, QPixmap().fromImage(img.scaled(QSize(size, size), Qt::KeepAspectRatio))); + painter.drawPixmap(x, y, QPixmap().fromImage(img.scaled(QSize(size, size), Qt::KeepAspectRatio, Qt::SmoothTransformation))); x += size + 1; if (x >= dragPixmap.width()) { x = 0; y += size + 1; } if (y >= dragPixmap.height()) { break; } } return dragPixmap; } void KisNodeView::resizeEvent(QResizeEvent * event) { KisNodeViewColorScheme scm; header()->setStretchLastSection(false); header()->setOffset(-scm.visibilityColumnWidth()); header()->resizeSection(0, event->size().width() - scm.visibilityColumnWidth()); setIndentation(scm.indentation()); QTreeView::resizeEvent(event); } void KisNodeView::paintEvent(QPaintEvent *event) { event->accept(); QTreeView::paintEvent(event); // Paint the line where the slide should go if (isDragging() && (displayMode() == KisNodeView::ThumbnailMode)) { QSize size(visualRect(model()->index(0, 0, QModelIndex())).width(), visualRect(model()->index(0, 0, QModelIndex())).height()); int numberRow = cursorPageIndex(); int scrollBarValue = verticalScrollBar()->value(); QPoint point1(0, numberRow * size.height() - scrollBarValue); QPoint point2(size.width(), numberRow * size.height() - scrollBarValue); QLineF line(point1, point2); QPainter painter(this->viewport()); QPen pen = QPen(palette().brush(QPalette::Highlight), 8); pen.setCapStyle(Qt::RoundCap); painter.setPen(pen); painter.setOpacity(0.8); painter.drawLine(line); } } void KisNodeView::drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const { Q_UNUSED(painter); Q_UNUSED(rect); Q_UNUSED(index); /** * Noop... Everything is going to be painted by KisNodeDelegate. * So this override basically disables painting of Qt's branch-lines. */ } void KisNodeView::dropEvent(QDropEvent *ev) { if (displayMode() == KisNodeView::ThumbnailMode) { setDraggingFlag(false); ev->accept(); clearSelection(); if (!model()) { return; } int newIndex = cursorPageIndex(); model()->dropMimeData(ev->mimeData(), ev->dropAction(), newIndex, -1, QModelIndex()); return; } QTreeView::dropEvent(ev); DRAG_WHILE_DRAG_WORKAROUND_STOP(); } int KisNodeView::cursorPageIndex() const { QSize size(visualRect(model()->index(0, 0, QModelIndex())).width(), visualRect(model()->index(0, 0, QModelIndex())).height()); int scrollBarValue = verticalScrollBar()->value(); QPoint cursorPosition = QWidget::mapFromGlobal(QCursor::pos()); int numberRow = (cursorPosition.y() + scrollBarValue) / size.height(); //If cursor is at the half button of the page then the move action is performed after the slide, otherwise it is //performed before the page if (abs((cursorPosition.y() + scrollBarValue) - size.height()*numberRow) > (size.height()/2)) { numberRow++; } if (numberRow > model()->rowCount(QModelIndex())) { numberRow = model()->rowCount(QModelIndex()); } return numberRow; } void KisNodeView::dragEnterEvent(QDragEnterEvent *ev) { DRAG_WHILE_DRAG_WORKAROUND_START(); QTreeView::dragEnterEvent(ev); } void KisNodeView::dragMoveEvent(QDragMoveEvent *ev) { DRAG_WHILE_DRAG_WORKAROUND_START(); if (displayMode() == KisNodeView::ThumbnailMode) { ev->accept(); if (!model()) { return; } QTreeView::dragMoveEvent(ev); setDraggingFlag(); viewport()->update(); return; } QTreeView::dragMoveEvent(ev); } void KisNodeView::dragLeaveEvent(QDragLeaveEvent *e) { if (displayMode() == KisNodeView::ThumbnailMode) { setDraggingFlag(false); } else { QTreeView::dragLeaveEvent(e); } DRAG_WHILE_DRAG_WORKAROUND_STOP(); } bool KisNodeView::isDragging() const { return m_draggingFlag; } void KisNodeView::setDraggingFlag(bool flag) { m_draggingFlag = flag; } diff --git a/libs/ui/kis_custom_pattern.cc b/libs/ui/kis_custom_pattern.cc index d31fcf2ece..a452a6aee6 100644 --- a/libs/ui/kis_custom_pattern.cc +++ b/libs/ui/kis_custom_pattern.cc @@ -1,175 +1,175 @@ /* * Copyright (c) 2006 Bart Coppens * * 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 "kis_custom_pattern.h" #include #include #include #include #include #include #include #include #include #include "KisDocument.h" #include "KisViewManager.h" #include "kis_image.h" #include "kis_layer.h" #include "kis_paint_device.h" #include #include "kis_resource_server_provider.h" #include "kis_paint_layer.h" KisCustomPattern::KisCustomPattern(QWidget *parent, const char* name, const QString& caption, KisViewManager* view) : KisWdgCustomPattern(parent, name), m_view(view) { Q_ASSERT(m_view); setWindowTitle(caption); m_pattern = 0; preview->setScaledContents(true); KoResourceServer* rServer = KoResourceServerProvider::instance()->patternServer(false); m_rServerAdapter = QSharedPointer(new KoResourceServerAdapter(rServer)); connect(addButton, SIGNAL(pressed()), this, SLOT(slotAddPredefined())); connect(patternButton, SIGNAL(pressed()), this, SLOT(slotUsePattern())); connect(updateButton, SIGNAL(pressed()), this, SLOT(slotUpdateCurrentPattern())); connect(cmbSource, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateCurrentPattern())); } KisCustomPattern::~KisCustomPattern() { delete m_pattern; } void KisCustomPattern::slotUpdateCurrentPattern() { delete m_pattern; m_pattern = 0; if (m_view && m_view->image()) { createPattern(); if (m_pattern) { const qint32 maxSize = 150; if ((m_pattern->width() > maxSize) || (m_pattern->height() > maxSize)) { float aspectRatio = (float)m_pattern->width() / m_pattern->height(); qint32 scaledWidth, scaledHeight; if (m_pattern->width() > m_pattern->height()) { scaledWidth = maxSize; scaledHeight = maxSize / aspectRatio; } else { scaledWidth = maxSize * aspectRatio; scaledHeight = maxSize; } if (scaledWidth == 0) scaledWidth++; if (scaledHeight == 0) scaledHeight++; QPixmap scaledPixmap = QPixmap::fromImage(m_pattern->pattern()); - preview->setPixmap(scaledPixmap.scaled(scaledWidth, scaledHeight)); + preview->setPixmap(scaledPixmap.scaled(scaledWidth, scaledHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation)); } else { preview->setPixmap(QPixmap::fromImage(m_pattern->pattern())); } } } } void KisCustomPattern::slotAddPredefined() { if (!m_pattern) return; // Save in the directory that is likely to be: ~/.kde/share/apps/krita/patterns // a unique file with this pattern name QString dir = KoResourceServerProvider::instance()->patternServer()->saveLocation(); QString extension; QString tempFileName; { QTemporaryFile file(dir + QLatin1String("/krita_XXXXXX") + QLatin1String(".pat") ); file.setAutoRemove(false); file.open(); tempFileName = file.fileName(); } // Save it to that file m_pattern->setFilename(tempFileName); // Add it to the pattern server, so that it automatically gets to the mediators, and // so to the other pattern choosers can pick it up, if they want to m_rServerAdapter->addResource(m_pattern->clone()); } void KisCustomPattern::slotUsePattern() { if (!m_pattern) return; KoPattern* copy = m_pattern->clone(); Q_CHECK_PTR(copy); emit(activatedResource(copy)); } void KisCustomPattern::createPattern() { if (!m_view) return; KisPaintDeviceSP dev; QString name; KisImageWSP image = m_view->image(); if (!image) return; QRect rc = image->bounds(); if (cmbSource->currentIndex() == 0) { dev = m_view->activeNode()->projection(); name = m_view->activeNode()->name(); QRect rc2 = dev->exactBounds(); rc = rc.intersected(rc2); } else { image->lock(); dev = image->projection(); image->unlock(); name = image->objectName(); } if (!dev) return; // warn when creating large patterns QSize size = rc.size(); if (size.width() > 1000 || size.height() > 1000) { lblWarning->setText(i18n("The current image is too big to create a pattern. " "The pattern will be scaled down.")); size.scale(1000, 1000, Qt::KeepAspectRatio); } QString dir = KoResourceServerProvider::instance()->patternServer()->saveLocation(); m_pattern = new KoPattern(dev->createThumbnail(size.width(), size.height(), rc, KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::internalConversionFlags()), name, dir); } diff --git a/libs/ui/kis_splash_screen.cpp b/libs/ui/kis_splash_screen.cpp index 501b5a53a5..7a6299b705 100644 --- a/libs/ui/kis_splash_screen.cpp +++ b/libs/ui/kis_splash_screen.cpp @@ -1,182 +1,182 @@ /* * Copyright (c) 2014 Boudewijn Rempt * * 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 "kis_splash_screen.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include KisSplashScreen::KisSplashScreen(const QString &version, const QPixmap &pixmap, bool themed, QWidget *parent, Qt::WindowFlags f) : QWidget(parent, Qt::SplashScreen | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | f), m_themed(themed) { setupUi(this); setWindowIcon(KisIconUtils::loadIcon("calligrakrita")); QString color = colorString(); // Maintain the aspect ratio on high DPI screens when scaling #ifdef Q_OS_MAC lblSplash->setPixmap(pixmap); #else - lblSplash->setPixmap(pixmap.scaled(lblSplash->width(),lblSplash->height(),Qt::KeepAspectRatio)); + lblSplash->setPixmap(pixmap.scaled(lblSplash->width(),lblSplash->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); #endif bnClose->hide(); connect(bnClose, SIGNAL(clicked()), this, SLOT(close())); chkShowAtStartup->hide(); connect(chkShowAtStartup, SIGNAL(toggled(bool)), this, SLOT(toggleShowAtStartup(bool))); KConfigGroup cfg( KSharedConfig::openConfig(), "SplashScreen"); bool hideSplash = cfg.readEntry("HideSplashAfterStartup", false); chkShowAtStartup->setChecked(hideSplash); lblLinks->setTextFormat(Qt::RichText); lblLinks->setText(i18n("" "" "" "

Links

" "

Support Krita

" "

Getting Started

" "

Manual

" "

Krita Website

" "

User Community

" "

Source Code

" "

Krita on Steam

" "" "", color)); lblVersion->setText(i18n("Version: %1", version)); lblVersion->setStyleSheet("color:" + color); updateText(); connect(lblRecent, SIGNAL(linkActivated(QString)), SLOT(linkClicked(QString))); connect(&m_timer, SIGNAL(timeout()), SLOT(raise())); m_timer.setSingleShot(true); m_timer.start(10); } void KisSplashScreen::resizeEvent(QResizeEvent *event) { QWidget::resizeEvent(event); updateText(); } void KisSplashScreen::updateText() { QString color = colorString(); KConfigGroup cfg2( KSharedConfig::openConfig(), "RecentFiles"); int i = 1; QString recent = i18n("" "" "" "

Recent Files

", color); QString path; QStringList recentfiles; QFontMetrics metrics(lblRecent->font()); do { path = cfg2.readPathEntry(QString("File%1").arg(i), QString()); if (!path.isEmpty()) { QString name = cfg2.readPathEntry(QString("Name%1").arg(i), QString()); QUrl url(path); if (name.isEmpty()) { name = url.fileName(); } name = metrics.elidedText(name, Qt::ElideMiddle, lblRecent->width()); if (!url.isLocalFile() || QFile::exists(url.toLocalFile())) { recentfiles.insert(0, QString("

%2

").arg(path).arg(name).arg(color)); } } i++; } while (!path.isEmpty() || i <= 8); recent += recentfiles.join("\n"); recent += "" ""; lblRecent->setText(recent); } QString KisSplashScreen::colorString() const { QString color = "#FFFFFF"; if (m_themed && qApp->palette().background().color().value() > 100) { color = "#000000"; } return color; } void KisSplashScreen::repaint() { QWidget::repaint(); QApplication::flush(); } void KisSplashScreen::show() { QRect r(QPoint(), sizeHint()); resize(r.size()); move(QApplication::desktop()->availableGeometry().center() - r.center()); if (isVisible()) { repaint(); } m_timer.setSingleShot(true); m_timer.start(1); QWidget::show(); } void KisSplashScreen::toggleShowAtStartup(bool toggle) { KConfigGroup cfg( KSharedConfig::openConfig(), "SplashScreen"); cfg.writeEntry("HideSplashAfterStartup", toggle); } void KisSplashScreen::linkClicked(const QString &link) { KisPart::instance()->openExistingFile(QUrl::fromLocalFile(link)); if (isTopLevel()) { close(); } } diff --git a/libs/vectorimage/libemf/demo/EmfViewer.cpp b/libs/vectorimage/libemf/demo/EmfViewer.cpp index b0c65ffc98..4730e1a506 100644 --- a/libs/vectorimage/libemf/demo/EmfViewer.cpp +++ b/libs/vectorimage/libemf/demo/EmfViewer.cpp @@ -1,100 +1,99 @@ /* Copyright 2008 Brad Hards Copyright 2008 Inge Wallin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either + License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + This library 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 Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public + You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "EmfViewer.h" #include #include #include #include "../EmfOutputPainterStrategy.h" EmfViewer::EmfViewer( QSize &size ) : QMainWindow() { m_size = size; setWindowTitle( "EMF Demo Viewer" ); QMenu *fileMenu = menuBar()->addMenu( "&File" ); // The "Open" action m_fileOpenAction->setShortcut( Qt::CTRL + Qt::Key_O ); m_fileOpenAction = fileMenu->addAction( "&Open", this, SLOT( slotOpenFile() ) ); fileMenu->addSeparator(); // The "Quit" action m_fileQuitAction->setShortcut( Qt::CTRL + Qt::Key_Q ); m_fileQuitAction = fileMenu->addAction( "&Quit", qApp, SLOT( closeAllWindows() ) ); // Set a suitably large size. resize( m_size + QSize( 50, 50 ) ); // ...and finably create the label that will show everything. m_label = new QLabel(this); setCentralWidget( m_label ); } EmfViewer::~EmfViewer() { } void EmfViewer::loadFile( const QString &fileName ) { Parser parser; // The image that the EMF parser should paint on. QImage image( m_size, QImage::Format_ARGB32_Premultiplied ); QPainter painter( &image ); OutputPainterStrategy output( painter, m_size ); parser.setOutput( &output ); parser.load( QString( fileName ) ); QPixmap pixmap = QPixmap::fromImage( image ); - m_label->setPixmap( pixmap.scaled( m_size, Qt::KeepAspectRatio, - Qt::SmoothTransformation ) ); - + m_label->setPixmap( pixmap.scaled(m_size, Qt::KeepAspectRatio, Qt::SmoothTransformation)); + m_label->show(); } // ---------------------------------------------------------------- // Slots void EmfViewer::slotOpenFile() { QString fileName = QFileDialog::getOpenFileName(this, "Open EMF document", QDir::homePath(), "EMF Documents (*.emf)" ); if (fileName.isEmpty()) { return; } loadFile( fileName ); } #include diff --git a/libs/widgets/KoResourceModel.cpp b/libs/widgets/KoResourceModel.cpp index 2094f2f098..55515cf57a 100644 --- a/libs/widgets/KoResourceModel.cpp +++ b/libs/widgets/KoResourceModel.cpp @@ -1,320 +1,320 @@ /* This file is part of the KDE project * Copyright (C) 2008-2009 Jan Hambrecht * Copyright (c) 2013 Sascha Suelzer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KoResourceModel.h" #include #include #include #include #include KoResourceModel::KoResourceModel(QSharedPointer resourceAdapter, QObject * parent) : KoResourceModelBase(parent) , m_resourceAdapter(resourceAdapter) , m_columnCount(4) { Q_ASSERT(m_resourceAdapter); m_resourceAdapter->connectToResourceServer(); connect(m_resourceAdapter.data(), SIGNAL(resourceAdded(KoResource*)), this, SLOT(resourceAdded(KoResource*))); connect(m_resourceAdapter.data(), SIGNAL(removingResource(KoResource*)), this, SLOT(resourceRemoved(KoResource*))); connect(m_resourceAdapter.data(), SIGNAL(resourceChanged(KoResource*)), this, SLOT(resourceChanged(KoResource*))); connect(m_resourceAdapter.data(), SIGNAL(tagsWereChanged()), this, SLOT(tagBoxEntryWasModified())); connect(m_resourceAdapter.data(), SIGNAL(tagCategoryWasAdded(QString)), this, SLOT(tagBoxEntryWasAdded(QString))); connect(m_resourceAdapter.data(), SIGNAL(tagCategoryWasRemoved(QString)), this, SLOT(tagBoxEntryWasRemoved(QString))); } KoResourceModel::~KoResourceModel() { if (!m_currentTag.isEmpty()) { KConfigGroup group = KSharedConfig::openConfig()->group("SelectedTags"); group.writeEntry(serverType(), m_currentTag); } } int KoResourceModel::rowCount( const QModelIndex &/*parent*/ ) const { int resourceCount = m_resourceAdapter->resources().count(); if (!resourceCount) return 0; return static_cast(ceil(static_cast(resourceCount) / m_columnCount)); } int KoResourceModel::columnCount ( const QModelIndex & ) const { return m_columnCount; } QVariant KoResourceModel::data( const QModelIndex &index, int role ) const { if( ! index.isValid() ) return QVariant(); switch( role ) { case Qt::DisplayRole: { KoResource * resource = static_cast(index.internalPointer()); if( ! resource ) return QVariant(); QString resName = i18n( resource->name().toUtf8().data()); if (m_resourceAdapter->assignedTagsList(resource).count()) { QString taglist = m_resourceAdapter->assignedTagsList(resource).join("] , ["); QString tagListToolTip = QString(" - %1: [%2]").arg(i18n("Tags"), taglist); return QVariant( resName + tagListToolTip ); } return QVariant( resName ); } case Qt::DecorationRole: { KoResource * resource = static_cast(index.internalPointer()); if( ! resource ) return QVariant(); return QVariant( resource->image() ); } case KoResourceModel::LargeThumbnailRole: { KoResource * resource = static_cast(index.internalPointer()); if( ! resource ) return QVariant(); QSize imageSize = resource->image().size(); QSize thumbSize( 100, 100 ); if(imageSize.height() > thumbSize.height() || imageSize.width() > thumbSize.width()) { qreal scaleW = static_cast( thumbSize.width() ) / static_cast( imageSize.width() ); qreal scaleH = static_cast( thumbSize.height() ) / static_cast( imageSize.height() ); qreal scale = qMin( scaleW, scaleH ); int thumbW = static_cast( imageSize.width() * scale ); int thumbH = static_cast( imageSize.height() * scale ); - return QVariant(resource->image().scaled( thumbW, thumbH, Qt::IgnoreAspectRatio )); + return QVariant(resource->image().scaled( thumbW, thumbH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); } else return QVariant(resource->image()); } default: return QVariant(); } } QModelIndex KoResourceModel::index ( int row, int column, const QModelIndex & ) const { int index = row * m_columnCount + column; const QList resources = m_resourceAdapter->resources(); if( index >= resources.count() || index < 0) return QModelIndex(); return createIndex( row, column, resources[index] ); } void KoResourceModel::doSafeLayoutReset(KoResource *activateAfterReformat) { emit beforeResourcesLayoutReset(activateAfterReformat); reset(); emit afterResourcesLayoutReset(); } void KoResourceModel::setColumnCount( int columnCount ) { if (columnCount != m_columnCount) { emit beforeResourcesLayoutReset(0); m_columnCount = columnCount; reset(); emit afterResourcesLayoutReset(); } } void KoResourceModel::resourceAdded(KoResource *resource) { int newIndex = m_resourceAdapter->resources().indexOf(resource); if (newIndex >= 0) { doSafeLayoutReset(0); } } void KoResourceModel::resourceRemoved(KoResource *resource) { Q_UNUSED(resource); KoResource *first = !m_resourceAdapter->resources().isEmpty() ? m_resourceAdapter->resources().first() : 0; doSafeLayoutReset(first); } void KoResourceModel::resourceChanged(KoResource* resource) { int resourceIndex = m_resourceAdapter->resources().indexOf(resource); int row = resourceIndex / columnCount(); int column = resourceIndex % columnCount(); QModelIndex modelIndex = index(row, column); if (!modelIndex.isValid()) { return; } emit dataChanged(modelIndex, modelIndex); } void KoResourceModel::tagBoxEntryWasModified() { m_resourceAdapter->updateServer(); emit tagBoxEntryModified(); } void KoResourceModel::tagBoxEntryWasAdded(const QString& tag) { emit tagBoxEntryAdded(tag); } void KoResourceModel::tagBoxEntryWasRemoved(const QString& tag) { emit tagBoxEntryRemoved(tag); } QModelIndex KoResourceModel::indexFromResource(KoResource* resource) const { int resourceIndex = m_resourceAdapter->resources().indexOf(resource); if (columnCount() > 0) { int row = resourceIndex / columnCount(); int column = resourceIndex % columnCount(); return index(row, column); } return QModelIndex(); } QString KoResourceModel::extensions() const { return m_resourceAdapter->extensions(); } void KoResourceModel::importResourceFile(const QString &filename) { m_resourceAdapter->importResourceFile(filename); } void KoResourceModel::importResourceFile(const QString & filename, bool fileCreation) { m_resourceAdapter->importResourceFile(filename, fileCreation); } bool KoResourceModel::removeResource(KoResource* resource) { return m_resourceAdapter->removeResource(resource); } void KoResourceModel::removeResourceFile(const QString &filename) { m_resourceAdapter->removeResourceFile(filename); } QStringList KoResourceModel::assignedTagsList(KoResource *resource) const { return m_resourceAdapter->assignedTagsList(resource); } void KoResourceModel::addTag(KoResource* resource, const QString& tag) { m_resourceAdapter->addTag(resource, tag); emit tagBoxEntryAdded(tag); } void KoResourceModel::deleteTag(KoResource *resource, const QString &tag) { m_resourceAdapter->deleteTag(resource, tag); } QStringList KoResourceModel::tagNamesList() const { return m_resourceAdapter->tagNamesList(); } QStringList KoResourceModel::searchTag(const QString& lineEditText) { return m_resourceAdapter->searchTag(lineEditText); } void KoResourceModel::searchTextChanged(const QString& searchString) { m_resourceAdapter->searchTextChanged(searchString); } void KoResourceModel::enableResourceFiltering(bool enable) { m_resourceAdapter->enableResourceFiltering(enable); } void KoResourceModel::setCurrentTag(const QString& currentTag) { m_currentTag = currentTag; m_resourceAdapter->setCurrentTag(currentTag); } void KoResourceModel::updateServer() { m_resourceAdapter->updateServer(); } int KoResourceModel::resourcesCount() const { return m_resourceAdapter->resources().count(); } QList KoResourceModel::currentlyVisibleResources() const { return m_resourceAdapter->resources(); } void KoResourceModel::tagCategoryMembersChanged() { m_resourceAdapter->tagCategoryMembersChanged(); } void KoResourceModel::tagCategoryAdded(const QString& tag) { m_resourceAdapter->tagCategoryAdded(tag); } void KoResourceModel::tagCategoryRemoved(const QString& tag) { m_resourceAdapter->tagCategoryRemoved(tag); } QString KoResourceModel::serverType() const { return m_resourceAdapter->serverType(); } QList< KoResource* > KoResourceModel::serverResources() const { return m_resourceAdapter->serverResources(); } diff --git a/plugins/dockers/advancedcolorselector/kis_common_colors_recalculation_runner.cpp b/plugins/dockers/advancedcolorselector/kis_common_colors_recalculation_runner.cpp index 9a14917d45..b9e1982416 100644 --- a/plugins/dockers/advancedcolorselector/kis_common_colors_recalculation_runner.cpp +++ b/plugins/dockers/advancedcolorselector/kis_common_colors_recalculation_runner.cpp @@ -1,213 +1,213 @@ #include "kis_common_colors_recalculation_runner.h" #include #include #include "KoColor.h" #include "KoColorSpaceRegistry.h" #include "kis_common_colors.h" enum ColorAxis {RedAxis=0, GreenAxis, BlueAxis}; class Color { public: Color(QRgb rgb) : r(qRed(rgb)), g(qGreen(rgb)), b(qBlue(rgb)) {} unsigned char r; unsigned char g; unsigned char b; inline unsigned char operator[](ColorAxis i) const { if(i==RedAxis) return r; if(i==GreenAxis) return g; return b; } }; class VBox { QList m_colors; public: VBox(QList rgbList) { QList colorList; for(int i=0; i colorList) : m_colors(colorList) {} int population() const { return m_colors.size(); } VBox divide() { ColorAxis axis = biggestAxis(); Q_ASSERT(axisSize(axis)>=3); unsigned char divpos = divPos(axis); QList newVBoxColors; for(int i=m_colors.size()-1; i>=0; i--) { Color c = m_colors.at(i); if(c[axis]>divpos) { m_colors.removeAt(i); newVBoxColors.append(c); } } return VBox(newVBoxColors); } QRgb mean() const { int r=0; int g=0; int b=0; for(int i=0;i0); return qRgb(r/size, g/size, b/size); } unsigned char axisSize(ColorAxis axis) const { unsigned char valMin = 255; unsigned char valMax = 0; for(int i=0; ivalMax) valMax=m_colors.at(i)[axis]; if(m_colors.at(i)[axis]sG && sR>sB) return RedAxis; if(sG>sR && sG>sB) return GreenAxis; return BlueAxis; } private: // unsigned char divPos(ColorAxis axis) const // { // QList values; // for(int i=0;im_colors.at(i)[axis]) min=m_colors.at(i)[axis]; if(maxsetColors(extractColors()); } QList KisCommonColorsRecalculationRunner::extractColors() { QList colors = getColors(); VBox startBox(colors); QList boxes; boxes.append(startBox); while (boxes.size()m_numColors*3/5) { int biggestBox=-1; int biggestBoxPopulation=-1; for(int i=0; ibiggestBoxPopulation && boxes.at(i).axisSize(boxes.at(i).biggestAxis())>=3) { biggestBox=i; biggestBoxPopulation=boxes.at(i).population(); } } if(biggestBox==-1 || boxes[biggestBox].population()<=3) break; VBox newBox = boxes[biggestBox].divide(); boxes.append(newBox); } while (boxes.size()m_numColors) { int biggestBox=-1; int biggestBoxAxisSize=-1; for(int i=0; ibiggestBoxAxisSize && boxes.at(i).axisSize(boxes.at(i).biggestAxis())>=3) { biggestBox=i; biggestBoxAxisSize=boxes.at(i).axisSize(boxes.at(i).biggestAxis()); } } if(biggestBox==-1 || boxes[biggestBox].population()<=3) break; VBox newBox = boxes[biggestBox].divide(); boxes.append(newBox); } const KoColorSpace* colorSpace = KoColorSpaceRegistry::instance()->rgb8(); QList colorList; for(int i=0; i=1) { colorList.append(KoColor(QColor(boxes.at(i).mean()), colorSpace)); } } return colorList; } QList KisCommonColorsRecalculationRunner::getColors() { int width = m_imageData.width(); int height = m_imageData.height(); QImage tmpImage; int pixelCount = height*width; if(pixelCount> (1<<16)) { qreal factor = sqrt((1<<16)/(qreal) pixelCount); - tmpImage=m_imageData.scaledToWidth(width*factor); + tmpImage = m_imageData.scaledToWidth(width*factor); } else { - tmpImage=m_imageData; + tmpImage = m_imageData; } width=tmpImage.width(); height=tmpImage.height(); QSet colorList; for (int i=0; i * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; version 2.1 of the License. * * This library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser 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 "imagedocker_dock.h" #include "image_strip_scene.h" #include "image_view.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "ui_wdgimagedocker.h" #include "ui_wdgImageViewPopup.h" /////////////////////////////////////////////////////////////////////////////// // --------- ImageFilter --------------------------------------------------- // class ImageFilter: public QSortFilterProxyModel { virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const { QFileSystemModel* model = static_cast(sourceModel()); QModelIndex index = sourceModel()->index(source_row, 0, source_parent); if(model->isDir(index)) return true; QString ext = model->fileInfo(index).suffix().toLower(); if(s_supportedImageFormats.isEmpty()) { s_supportedImageFormats = QImageReader::supportedImageFormats(); } //QImageReader::supportedImageFormats return a list with mixed-case ByteArrays so //iterate over it manually to make it possible to do toLower(). Q_FOREACH (const QByteArray& format, s_supportedImageFormats) { if(format.toLower() == ext.toUtf8()) { return true; } } return false; } virtual bool filterAcceptsColumn(int source_column, const QModelIndex& source_parent) const { Q_UNUSED(source_parent); return source_column == 0; } static QList s_supportedImageFormats; }; QList ImageFilter::s_supportedImageFormats; /////////////////////////////////////////////////////////////////////////////// // --------- ImageListModel ------------------------------------------------ // class ImageListModel: public QAbstractListModel { struct Data { QPixmap icon; QString text; qint64 id; }; public: void addImage(const QPixmap& pixmap, const QString& text, qint64 id) { Data data; - data.icon = pixmap.scaled(70, 70, Qt::KeepAspectRatio); + data.icon = pixmap.scaled(70, 70, Qt::KeepAspectRatio, Qt::SmoothTransformation); data.text = text; data.id = id; emit layoutAboutToBeChanged(); m_data.push_back(data); emit layoutChanged(); } qint64 imageID(int index) const { return m_data[index].id; } void removeImage(qint64 id) { typedef QList::iterator Iterator; for(Iterator data=m_data.begin(); data!=m_data.end(); ++data) { if(data->id == id) { emit layoutAboutToBeChanged(); m_data.erase(data); emit layoutChanged(); return; } } } int indexFromID(qint64 id) { for(int i=0; i m_data; }; /////////////////////////////////////////////////////////////////////////////// // --------- ImageDockerUI ------------------------------------------------- // struct ImageDockerUI: public QWidget, public Ui_wdgImageDocker { ImageDockerUI() { setupUi(this); } }; /////////////////////////////////////////////////////////////////////////////// // --------- PopupWidgetUI ------------------------------------------------- // struct PopupWidgetUI: public QWidget, public Ui_wdgImageViewPopup { PopupWidgetUI() { setupUi(this); } }; /////////////////////////////////////////////////////////////////////////////// // --------- ImageDockerDock ----------------------------------------------- // ImageDockerDock::ImageDockerDock(): QDockWidget(i18n("Reference Images")), m_canvas(0), m_currImageID(-1) { m_ui = new ImageDockerUI(); m_popupUi = new PopupWidgetUI(); m_zoomButtons = new QButtonGroup(); m_imgListModel = new ImageListModel(); m_imageStripScene = new ImageStripScene(); m_model = new QFileSystemModel(); m_proxyModel = new ImageFilter(); m_proxyModel->setSourceModel(m_model); m_proxyModel->setDynamicSortFilter(true); m_ui->bnBack->setIcon(KisIconUtils::loadIcon("arrow-left")); m_ui->bnUp->setIcon(KisIconUtils::loadIcon("arrow-up")); m_ui->bnHome->setIcon(KisIconUtils::loadIcon("go-home")); m_ui->bnImgPrev->setIcon(KisIconUtils::loadIcon("arrow-left")); m_ui->bnImgNext->setIcon(KisIconUtils::loadIcon("arrow-right")); m_ui->bnImgClose->setIcon(KisIconUtils::loadIcon("window-close")); m_ui->thumbView->setScene(m_imageStripScene); m_ui->treeView->setModel(m_proxyModel); m_ui->cmbImg->setModel(m_imgListModel); m_ui->bnPopup->setIcon(KisIconUtils::loadIcon("zoom-original")); m_ui->bnPopup->setPopupWidget(m_popupUi); m_popupUi->zoomSlider->setRange(5, 500); m_popupUi->zoomSlider->setValue(100); m_zoomButtons->addButton(m_popupUi->bnZoomFit , ImageView::VIEW_MODE_FIT); m_zoomButtons->addButton(m_popupUi->bnZoomAdjust, ImageView::VIEW_MODE_ADJUST); m_zoomButtons->addButton(m_popupUi->bnZoom25 , 25); m_zoomButtons->addButton(m_popupUi->bnZoom50 , 50); m_zoomButtons->addButton(m_popupUi->bnZoom75 , 75); m_zoomButtons->addButton(m_popupUi->bnZoom100 , 100); installEventFilter(this); m_ui->cmbPath->addItem(KisIconUtils::loadIcon("folder-pictures"), QDesktopServices::storageLocation(QDesktopServices::PicturesLocation)); m_ui->cmbPath->addItem(KisIconUtils::loadIcon("folder-documents"), QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)); m_ui->cmbPath->addItem(KisIconUtils::loadIcon("go-home"), QDesktopServices::storageLocation(QDesktopServices::HomeLocation)); Q_FOREACH (const QFileInfo &info, QDir::drives()) { m_ui->cmbPath->addItem(KisIconUtils::loadIcon("drive-harddisk"), info.absolutePath()); } connect(m_ui->cmbPath, SIGNAL(activated(const QString&)), SLOT(slotChangeRoot(const QString&))); m_model->setRootPath(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation)); m_ui->treeView->setRootIndex(m_proxyModel->mapFromSource(m_model->index(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation)))); connect(m_ui->treeView , SIGNAL(doubleClicked(const QModelIndex&)) , SLOT(slotItemDoubleClicked(const QModelIndex&))); connect(m_ui->bnBack , SIGNAL(clicked(bool)) , SLOT(slotBackButtonClicked())); connect(m_ui->bnHome , SIGNAL(clicked(bool)) , SLOT(slotHomeButtonClicked())); connect(m_ui->bnUp , SIGNAL(clicked(bool)) , SLOT(slotUpButtonClicked())); connect(m_imageStripScene , SIGNAL(sigImageActivated(const QString&)) , SLOT(slotOpenImage(QString))); connect(m_ui->bnImgNext , SIGNAL(clicked(bool)) , SLOT(slotNextImage())); connect(m_ui->bnImgPrev , SIGNAL(clicked(bool)) , SLOT(slotPrevImage())); connect(m_ui->bnImgClose , SIGNAL(clicked(bool)) , SLOT(slotCloseCurrentImage())); connect(m_ui->cmbImg , SIGNAL(activated(int)) , SLOT(slotImageChoosenFromComboBox(int))); connect(m_ui->imgView , SIGNAL(sigColorSelected(const QColor&)) , SLOT(slotColorSelected(const QColor))); connect(m_ui->imgView , SIGNAL(sigViewModeChanged(int, qreal)) , SLOT(slotViewModeChanged(int, qreal))); connect(m_popupUi->zoomSlider , SIGNAL(valueChanged(int)) , SLOT(slotZoomChanged(int))); connect(m_zoomButtons , SIGNAL(buttonClicked(int)) , SLOT(slotZoomChanged(int))); connect(m_zoomButtons , SIGNAL(buttonClicked(int)) , SLOT(slotCloseZoomPopup())); setWidget(m_ui); setAcceptDrops(true); } ImageDockerDock::~ImageDockerDock() { delete m_proxyModel; delete m_model; delete m_imageStripScene; delete m_imgListModel; delete m_zoomButtons; qDeleteAll(m_temporaryFiles); } void ImageDockerDock::dragEnterEvent(QDragEnterEvent *event) { event->setAccepted(event->mimeData()->hasImage() || event->mimeData()->hasUrls()); } void ImageDockerDock::dropEvent(QDropEvent *event) { QImage image; if (event->mimeData()->hasImage()) { image = qvariant_cast(event->mimeData()->imageData()); } if (!image.isNull()) { QTemporaryFile *file = new QTemporaryFile(QDir::tempPath () + QDir::separator() + "krita_reference_dnd_XXXXXX.png"); m_temporaryFiles.append(file); file->open(); image.save(file, "PNG"); file->close(); slotOpenImage(file->fileName()); } else if (event->mimeData()->hasUrls()) { QList urls = event->mimeData()->urls(); Q_FOREACH (const QUrl &url, urls) { QString path = url.path(); QFileInfo info(path); if (info.exists() && !QImageReader::imageFormat(path).isEmpty()) { slotOpenImage(path); } } } } void ImageDockerDock::showEvent(QShowEvent *) { if (m_imageStripScene->currentPath().isNull()) { updatePath(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation)); } } void ImageDockerDock::setCanvas(KoCanvasBase* canvas) { // Intentionally not disabled if there's no canvas // "Every connection you make emits a signal, so duplicate connections emit two signals" if(m_canvas) m_canvas->disconnectCanvasObserver(this); m_canvas = canvas; } void ImageDockerDock::addCurrentPathToHistory() { m_history.push_back(m_model->filePath(m_proxyModel->mapToSource(m_ui->treeView->rootIndex()))); } void ImageDockerDock::updatePath(const QString& path) { m_ui->bnBack->setDisabled(m_history.empty()); m_imageStripScene->setCurrentDirectory(path); } qint64 ImageDockerDock::generateImageID() const { static qint64 id = 0; return ++id; } void ImageDockerDock::setCurrentImage(qint64 imageID) { if(m_imgInfoMap.contains(m_currImageID)) m_imgInfoMap[m_currImageID].scrollPos = m_ui->imgView->getScrollPos(); m_ui->bnImgClose->setDisabled(imageID < 0); m_ui->bnPopup->setDisabled(imageID < 0); if(imageID < 0) { m_currImageID = -1; m_ui->imgView->setPixmap(QPixmap()); } else if(m_imgInfoMap.contains(imageID)) { ImageInfoIter info = m_imgInfoMap.find(imageID); m_ui->imgView->blockSignals(true); m_ui->imgView->setPixmap(info->pixmap); setZoom(*info); m_ui->imgView->blockSignals(false); m_ui->bnImgPrev->setDisabled(info == m_imgInfoMap.begin()); m_ui->bnImgNext->setDisabled((info+1) == m_imgInfoMap.end()); m_ui->cmbImg->blockSignals(true); m_ui->cmbImg->setCurrentIndex(m_imgListModel->indexFromID(imageID)); m_ui->cmbImg->blockSignals(false); m_currImageID = imageID; } } void ImageDockerDock::setZoom(const ImageInfo& info) { m_ui->imgView->setViewMode(info.viewMode, info.scale); m_ui->imgView->setScrollPos(info.scrollPos); int zoom = qRound(m_ui->imgView->getScale() * 100.0f); m_popupUi->zoomSlider->blockSignals(true); m_popupUi->zoomSlider->setValue(zoom); m_popupUi->zoomSlider->blockSignals(false); } // ------------ slots ------------------------------------------------- // void ImageDockerDock::slotItemDoubleClicked(const QModelIndex& index) { QModelIndex mappedIndex = m_proxyModel->mapToSource(index); mappedIndex = m_model->index(mappedIndex.row(), 0, mappedIndex.parent()); QString path(m_model->filePath(mappedIndex)); if(m_model->isDir(mappedIndex)) { addCurrentPathToHistory(); updatePath(path); m_ui->treeView->setRootIndex(m_proxyModel->mapFromSource(mappedIndex)); } else slotOpenImage(path); } void ImageDockerDock::slotBackButtonClicked() { if(!m_history.empty()) { QString path = m_history.last(); QModelIndex index = m_proxyModel->mapFromSource(m_model->index(path)); m_ui->treeView->setRootIndex(index); m_history.pop_back(); updatePath(path); } } void ImageDockerDock::slotHomeButtonClicked() { addCurrentPathToHistory(); QModelIndex index = m_proxyModel->mapFromSource(m_model->index(QDir::homePath())); m_ui->treeView->setRootIndex(index); updatePath(QDir::homePath()); } void ImageDockerDock::slotUpButtonClicked() { addCurrentPathToHistory(); QModelIndex index = m_proxyModel->mapToSource(m_ui->treeView->rootIndex()); QDir dir(m_model->filePath(index)); dir.makeAbsolute(); if(dir.cdUp()) { index = m_proxyModel->mapFromSource(m_model->index(dir.path())); m_ui->treeView->setRootIndex(index); updatePath(dir.path()); } } void ImageDockerDock::slotOpenImage(const QString& path) { QPixmap pixmap(path); if(!pixmap.isNull()) { QFileInfo fileInfo(path); ImageInfo imgInfo; imgInfo.id = generateImageID(); imgInfo.name = fileInfo.fileName(); imgInfo.path = fileInfo.absoluteFilePath(); imgInfo.viewMode = ImageView::VIEW_MODE_FIT; imgInfo.scale = 1.0f; imgInfo.pixmap = pixmap; imgInfo.scrollPos = QPoint(0, 0); m_imgInfoMap[imgInfo.id] = imgInfo; m_imgListModel->addImage(imgInfo.pixmap, imgInfo.name, imgInfo.id); setCurrentImage(imgInfo.id); m_ui->tabWidget->setCurrentIndex(1); } } void ImageDockerDock::slotCloseCurrentImage() { ImageInfoIter info = m_imgInfoMap.find(m_currImageID); if(info != m_imgInfoMap.end()) { ImageInfoIter next = info + 1; ImageInfoIter prev = info - 1; qint64 id = -1; if(next != m_imgInfoMap.end()) id = next->id; else if(info != m_imgInfoMap.begin()) id = prev->id; m_imgListModel->removeImage(info->id); m_imgInfoMap.erase(info); setCurrentImage(id); if(id < 0) m_ui->tabWidget->setCurrentIndex(0); } } void ImageDockerDock::slotNextImage() { ImageInfoIter info = m_imgInfoMap.find(m_currImageID); if(info != m_imgInfoMap.end()) { ++info; if(info != m_imgInfoMap.end()) setCurrentImage(info->id); } } void ImageDockerDock::slotPrevImage() { ImageInfoIter info = m_imgInfoMap.find(m_currImageID); if(info != m_imgInfoMap.end() && info != m_imgInfoMap.begin()) { --info; setCurrentImage(info->id); } } void ImageDockerDock::slotImageChoosenFromComboBox(int index) { setCurrentImage(m_imgListModel->imageID(index)); } void ImageDockerDock::slotZoomChanged(int zoom) { if(isImageLoaded()) { ImageInfoIter info = m_imgInfoMap.find(m_currImageID); switch(zoom) { case ImageView::VIEW_MODE_FIT: case ImageView::VIEW_MODE_ADJUST: info->viewMode = zoom; break; default: info->viewMode = ImageView::VIEW_MODE_FREE; info->scale = float(zoom) / 100.0f; break; } setZoom(*info); } } void ImageDockerDock::slotColorSelected(const QColor& color) { if (m_canvas) { m_canvas->resourceManager()->setForegroundColor(KoColor(color, KoColorSpaceRegistry::instance()->rgb8())); } } void ImageDockerDock::slotViewModeChanged(int viewMode, qreal scale) { if(isImageLoaded()) { m_imgInfoMap[m_currImageID].viewMode = viewMode; m_imgInfoMap[m_currImageID].scale = scale; int zoom = qRound(scale * 100.0); m_popupUi->zoomSlider->blockSignals(true); m_popupUi->zoomSlider->setValue(zoom); m_popupUi->zoomSlider->blockSignals(false); } } void ImageDockerDock::slotCloseZoomPopup() { m_ui->bnPopup->hidePopupWidget(); } void ImageDockerDock::slotChangeRoot(const QString &path) { m_model->setRootPath(path); m_ui->treeView->setRootIndex(m_proxyModel->mapFromSource(m_model->index(path))); updatePath(path); } bool ImageDockerDock::eventFilter(QObject *obj, QEvent *event) { Q_UNUSED(obj); if (event->type() == QEvent::Resize) { m_ui->treeView->setColumnWidth(0, width()); return true; } return false; } diff --git a/plugins/dockers/overview/overviewwidget.cc b/plugins/dockers/overview/overviewwidget.cc index a6e029610f..0d8af9dc2b 100644 --- a/plugins/dockers/overview/overviewwidget.cc +++ b/plugins/dockers/overview/overviewwidget.cc @@ -1,219 +1,219 @@ /* * Copyright (c) 2009 Cyrille Berger * Copyright (c) 2014 Sven Langkamp * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; version 2.1 of the License. * * This library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser 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 "overviewwidget.h" #include #include #include #include #include #include #include #include #include #include #include OverviewWidget::OverviewWidget(QWidget * parent) : QWidget(parent) , m_compressor(new KisSignalCompressor(500, KisSignalCompressor::POSTPONE, this)) , m_canvas(0) , m_dragging(false) { setMouseTracking(true); connect(m_compressor, SIGNAL(timeout()), SLOT(startUpdateCanvasProjection())); KisConfig cfg; QRgb c = cfg.readEntry("OverviewWidgetColor", 0xFF454C); m_outlineColor = QColor(c); } OverviewWidget::~OverviewWidget() { } void OverviewWidget::setCanvas(KoCanvasBase * canvas) { if (m_canvas) { m_canvas->image()->disconnect(this); } m_canvas = dynamic_cast(canvas); if (m_canvas) { connect(m_canvas->image(), SIGNAL(sigImageUpdated(QRect)), m_compressor, SLOT(start()), Qt::UniqueConnection); connect(m_canvas->image(), SIGNAL(sigSizeChanged(QPointF, QPointF)), m_compressor, SLOT(start()), Qt::UniqueConnection); connect(m_canvas->canvasController()->proxyObject, SIGNAL(canvasOffsetXChanged(int)), this, SLOT(update()), Qt::UniqueConnection); m_compressor->start(); } } QSize OverviewWidget::calculatePreviewSize() { QSize imageSize(m_canvas->image()->bounds().size()); imageSize.scale(size(), Qt::KeepAspectRatio); return imageSize; } QPointF OverviewWidget::previewOrigin() { return QPointF((width() - m_pixmap.width())/2.0f, (height() - m_pixmap.height())/2.0f); } QPolygonF OverviewWidget::previewPolygon() { if (m_canvas) { const KisCoordinatesConverter* converter = m_canvas->coordinatesConverter(); QPolygonF canvasPoly = QPolygonF(QRectF(m_canvas->canvasWidget()->rect())); QPolygonF imagePoly = converter->widgetToImage(canvasPoly); - + QTransform imageToPreview = imageToPreviewTransform(); - + return imageToPreview.map(imagePoly); } return QPolygonF(); } QTransform OverviewWidget::imageToPreviewTransform() { QTransform imageToPreview; imageToPreview.scale(calculatePreviewSize().width()/(float)m_canvas->image()->width(), calculatePreviewSize().height()/(float)m_canvas->image()->height()); return imageToPreview; } void OverviewWidget::startUpdateCanvasProjection() { if (!m_canvas) return; KisImageSP image = m_canvas->image(); QSize previewSize = calculatePreviewSize(); if (isVisible() && previewSize.isValid()) { QImage img = image->projection()-> createThumbnail(previewSize.width(), previewSize.height(), image->bounds()); m_pixmap = QPixmap::fromImage(img); } update(); } void OverviewWidget::showEvent(QShowEvent *event) { Q_UNUSED(event); m_compressor->start(); } void OverviewWidget::resizeEvent(QResizeEvent *event) { Q_UNUSED(event); if (m_canvas) { if (!m_pixmap.isNull()) { QSize newSize = calculatePreviewSize(); - m_pixmap = m_pixmap.scaled(newSize); + m_pixmap = m_pixmap.scaled(newSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); } m_compressor->start(); } } void OverviewWidget::mousePressEvent(QMouseEvent* event) { if (m_canvas) { QPointF previewPos = event->pos() - previewOrigin(); - + if (previewPolygon().containsPoint(previewPos, Qt::WindingFill)) { m_lastPos = previewPos; m_dragging = true; } } event->accept(); update(); } void OverviewWidget::mouseMoveEvent(QMouseEvent* event) { if (m_dragging) { QPointF previewPos = event->pos() - previewOrigin(); // position is mapped from preview image->image->canvas coordinates QTransform previewToImage = imageToPreviewTransform().inverted(); const KisCoordinatesConverter* converter = m_canvas->coordinatesConverter(); QPointF lastImagePos = previewToImage.map(m_lastPos); QPointF newImagePos = previewToImage.map(previewPos); - + QPointF lastWidgetPos = converter->imageToWidget(lastImagePos); QPointF newWidgetPos = converter->imageToWidget(newImagePos); - + QPointF diff = newWidgetPos - lastWidgetPos; m_canvas->canvasController()->pan(diff.toPoint()); m_lastPos = previewPos; } event->accept(); } void OverviewWidget::mouseReleaseEvent(QMouseEvent* event) { m_dragging = false; event->accept(); update(); } void OverviewWidget::wheelEvent(QWheelEvent* event) { float delta = event->delta(); - + if (delta > 0) { m_canvas->viewManager()->zoomController()->zoomAction()->zoomIn(); } else { m_canvas->viewManager()->zoomController()->zoomAction()->zoomOut(); } } void OverviewWidget::paintEvent(QPaintEvent* event) { QWidget::paintEvent(event); if (m_canvas) { QPainter p(this); p.translate(previewOrigin()); - + p.drawPixmap(0, 0, m_pixmap.width(), m_pixmap.height(), m_pixmap); QRect r = rect().translated(-previewOrigin().toPoint()); QPolygonF outline; outline << r.topLeft() << r.topRight() << r.bottomRight() << r.bottomLeft(); QPen pen; pen.setColor(m_outlineColor); pen.setStyle(Qt::DashLine); p.setPen(pen); p.drawPolygon(outline.intersected(previewPolygon())); pen.setStyle(Qt::SolidLine); p.setPen(pen); p.drawPolygon(previewPolygon()); } } diff --git a/plugins/paintops/libpaintop/kis_brush_chooser.cpp b/plugins/paintops/libpaintop/kis_brush_chooser.cpp index 156354ba3b..aa7e24c4bd 100644 --- a/plugins/paintops/libpaintop/kis_brush_chooser.cpp +++ b/plugins/paintops/libpaintop/kis_brush_chooser.cpp @@ -1,363 +1,363 @@ /* * Copyright (c) 2004 Adrian Page * Copyright (c) 2009 Sven Langkamp * Copyright (c) 2010 Cyrille Berger * Copyright (c) 2010 Lukáš Tvrdý * Copyright (C) 2011 Srikanth Tiyyagura * * 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 "kis_brush_chooser.h" #include #include #include #include #include #include #include #include #include #include #include #include #include "kis_brush_registry.h" #include "kis_brush_server.h" #include "widgets/kis_slider_spin_box.h" #include "widgets/kis_multipliers_double_slider_spinbox.h" #include "kis_spacing_selection_widget.h" #include "kis_signals_blocker.h" #include "kis_custom_brush_widget.h" #include "kis_clipboard_brush_widget.h" #include "kis_global.h" #include "kis_gbr_brush.h" #include "kis_debug.h" #include "kis_image.h" /// The resource item delegate for rendering the resource preview class KisBrushDelegate : public QAbstractItemDelegate { public: KisBrushDelegate(QObject * parent = 0) : QAbstractItemDelegate(parent) {} virtual ~KisBrushDelegate() {} /// reimplemented virtual void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const; /// reimplemented QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex &) const { return option.decorationSize; } }; void KisBrushDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { if (! index.isValid()) return; KisBrush *brush = static_cast(index.internalPointer()); QRect itemRect = option.rect; QImage thumbnail = brush->image(); if (thumbnail.height() > itemRect.height() || thumbnail.width() > itemRect.width()) { - thumbnail = thumbnail.scaled(itemRect.size() , Qt::KeepAspectRatio); + thumbnail = thumbnail.scaled(itemRect.size() , Qt::KeepAspectRatio, Qt::SmoothTransformation); } painter->save(); int dx = (itemRect.width() - thumbnail.width()) / 2; int dy = (itemRect.height() - thumbnail.height()) / 2; painter->drawImage(itemRect.x() + dx, itemRect.y() + dy, thumbnail); if (option.state & QStyle::State_Selected) { painter->setPen(QPen(option.palette.highlight(), 2.0)); painter->drawRect(option.rect); painter->setCompositionMode(QPainter::CompositionMode_HardLight); painter->setOpacity(0.65); painter->fillRect(option.rect, option.palette.highlight()); } painter->restore(); } KisBrushChooser::KisBrushChooser(QWidget *parent, const char *name) : QWidget(parent), m_stampBrushWidget(0), m_clipboardBrushWidget(0) { setObjectName(name); m_lbSize = new QLabel(i18n("Size:"), this); m_slSize = new KisDoubleSliderSpinBox(this); m_slSize->setRange(0, 1000, 2); m_slSize->setValue(5); m_slSize->setExponentRatio(3.0); m_slSize->setSuffix(i18n(" px")); m_slSize->setExponentRatio(3.0); QObject::connect(m_slSize, SIGNAL(valueChanged(qreal)), this, SLOT(slotSetItemSize(qreal))); m_lbRotation = new QLabel(i18n("Rotation:"), this); m_slRotation = new KisDoubleSliderSpinBox(this); m_slRotation->setRange(0, 360, 0); m_slRotation->setValue(0); m_slRotation->setSuffix(QChar(Qt::Key_degree)); QObject::connect(m_slRotation, SIGNAL(valueChanged(qreal)), this, SLOT(slotSetItemRotation(qreal))); m_lbSpacing = new QLabel(i18n("Spacing:"), this); m_slSpacing = new KisSpacingSelectionWidget(this); m_slSpacing->setSpacing(true, 1.0); connect(m_slSpacing, SIGNAL(sigSpacingChanged()), SLOT(slotSpacingChanged())); m_chkColorMask = new QCheckBox(i18n("Use color as mask"), this); QObject::connect(m_chkColorMask, SIGNAL(toggled(bool)), this, SLOT(slotSetItemUseColorAsMask(bool))); m_lbName = new QLabel(this); KisBrushResourceServer* rServer = KisBrushServer::instance()->brushServer(); QSharedPointer adapter(new KisBrushResourceServerAdapter(rServer)); m_itemChooser = new KoResourceItemChooser(adapter, this); m_itemChooser->showTaggingBar(true); m_itemChooser->setColumnCount(10); m_itemChooser->setRowHeight(30); m_itemChooser->setItemDelegate(new KisBrushDelegate(this)); m_itemChooser->setCurrentItem(0, 0); m_itemChooser->setSynced(true); connect(m_itemChooser, SIGNAL(resourceSelected(KoResource *)), this, SLOT(update(KoResource *))); QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setObjectName("main layout"); mainLayout->addWidget(m_lbName); mainLayout->addWidget(m_itemChooser, 10); QPushButton *stampButton = new QPushButton(KisIconUtils::loadIcon("list-add"), i18n("Stamp"), this); QPushButton *clipboardButton = new QPushButton(KisIconUtils::loadIcon("edit-paste"), i18n("Clipboard"), this); stampButton->setToolTip(i18n("Creates a brush tip from the current image selection." "\n If no selection is present the whole image will be used.")); clipboardButton->setToolTip(i18n("Creates a brush tip from the image in the clipboard.")); m_itemChooser->addCustomButton(stampButton, 2); m_itemChooser->addCustomButton(clipboardButton, 3); connect(stampButton, SIGNAL(clicked()), this, SLOT(slotOpenStampBrush())); connect(clipboardButton, SIGNAL(clicked()), SLOT(slotOpenClipboardBrush())); QGridLayout *spacingLayout = new QGridLayout(); spacingLayout->setObjectName("spacing grid layout"); mainLayout->addLayout(spacingLayout, 1); spacingLayout->addWidget(m_lbSize, 1, 0); spacingLayout->addWidget(m_slSize, 1, 1); spacingLayout->addWidget(m_lbRotation, 2, 0); spacingLayout->addWidget(m_slRotation, 2, 1); spacingLayout->addWidget(m_lbSpacing, 3, 0); spacingLayout->addWidget(m_slSpacing, 3, 1); spacingLayout->setColumnStretch(1, 3); QPushButton *resetBrushButton = new QPushButton(i18n("Reset Predefined Tip"), this); resetBrushButton->setToolTip(i18n("Reloads Spacing from file\nSets Scale to 1.0\nSets Rotation to 0.0")); connect(resetBrushButton, SIGNAL(clicked()), SLOT(slotResetBrush())); QHBoxLayout *resetHLayout = new QHBoxLayout(); resetHLayout->addWidget(m_chkColorMask, 0); resetHLayout->addWidget(resetBrushButton, 0, Qt::AlignRight); spacingLayout->addLayout(resetHLayout, 4, 0, 1, 2); update(m_itemChooser->currentResource()); } KisBrushChooser::~KisBrushChooser() { } void KisBrushChooser::setBrush(KisBrushSP _brush) { m_itemChooser->setCurrentResource(_brush.data()); update(_brush.data()); } void KisBrushChooser::slotResetBrush() { KisBrush *brush = dynamic_cast(m_itemChooser->currentResource()); if (brush) { brush->load(); brush->setScale(1.0); brush->setAngle(0.0); slotActivatedBrush(brush); update(brush); emit sigBrushChanged(); } } void KisBrushChooser::slotSetItemSize(qreal sizeValue) { KisBrush *brush = dynamic_cast(m_itemChooser->currentResource()); if (brush) { int brushWidth = brush->width(); brush->setScale(sizeValue / qreal(brushWidth)); slotActivatedBrush(brush); emit sigBrushChanged(); } } void KisBrushChooser::slotSetItemRotation(qreal rotationValue) { KisBrush *brush = dynamic_cast(m_itemChooser->currentResource()); if (brush) { brush->setAngle(rotationValue / 180.0 * M_PI); slotActivatedBrush(brush); emit sigBrushChanged(); } } void KisBrushChooser::slotSpacingChanged() { KisBrush *brush = dynamic_cast(m_itemChooser->currentResource()); if (brush) { brush->setSpacing(m_slSpacing->spacing()); brush->setAutoSpacing(m_slSpacing->autoSpacingActive(), m_slSpacing->autoSpacingCoeff()); slotActivatedBrush(brush); emit sigBrushChanged(); } } void KisBrushChooser::slotSetItemUseColorAsMask(bool useColorAsMask) { KisGbrBrush *brush = dynamic_cast(m_itemChooser->currentResource()); if (brush) { brush->setUseColorAsMask(useColorAsMask); slotActivatedBrush(brush); emit sigBrushChanged(); } } void KisBrushChooser::slotOpenStampBrush() { if(!m_stampBrushWidget) { m_stampBrushWidget = new KisCustomBrushWidget(this, i18n("Stamp"), m_image); m_stampBrushWidget->setModal(false); connect(m_stampBrushWidget, SIGNAL(sigNewPredefinedBrush(KoResource *)), SLOT(slotNewPredefinedBrush(KoResource *))); } QDialog::DialogCode result = (QDialog::DialogCode)m_stampBrushWidget->exec(); if(result) { update(m_itemChooser->currentResource()); } } void KisBrushChooser::slotOpenClipboardBrush() { if(!m_clipboardBrushWidget) { m_clipboardBrushWidget = new KisClipboardBrushWidget(this, i18n("Clipboard"), m_image); m_clipboardBrushWidget->setModal(true); connect(m_clipboardBrushWidget, SIGNAL(sigNewPredefinedBrush(KoResource *)), SLOT(slotNewPredefinedBrush(KoResource *))); } QDialog::DialogCode result = (QDialog::DialogCode)m_clipboardBrushWidget->exec(); if(result) { update(m_itemChooser->currentResource()); } } void KisBrushChooser::update(KoResource * resource) { KisBrush* brush = dynamic_cast(resource); if (brush) { QString text = QString("%1 (%2 x %3)") .arg(i18n(brush->name().toUtf8().data())) .arg(brush->width()) .arg(brush->height()); m_lbName->setText(text); m_slSpacing->setSpacing(brush->autoSpacingActive(), brush->autoSpacingActive() ? brush->autoSpacingCoeff() : brush->spacing()); m_slRotation->setValue(brush->angle() * 180 / M_PI); m_slSize->setValue(brush->width() * brush->scale()); // useColorAsMask support is only in gimp brush so far KisGbrBrush *gimpBrush = dynamic_cast(resource); if (gimpBrush) { m_chkColorMask->setChecked(gimpBrush->useColorAsMask()); } m_chkColorMask->setEnabled(brush->hasColor() && gimpBrush); slotActivatedBrush(brush); emit sigBrushChanged(); } } void KisBrushChooser::slotActivatedBrush(KoResource * resource) { KisBrush* brush = dynamic_cast(resource); if (m_brush != brush) { if (m_brush) { m_brush->clearBrushPyramid(); } m_brush = brush; if (m_brush) { m_brush->prepareBrushPyramid(); } } } void KisBrushChooser::slotNewPredefinedBrush(KoResource *resource) { m_itemChooser->setCurrentResource(resource); update(resource); } void KisBrushChooser::setBrushSize(qreal xPixels, qreal yPixels) { Q_UNUSED(yPixels); qreal oldWidth = m_brush->width() * m_brush->scale(); qreal newWidth = oldWidth + xPixels; newWidth = qMax(newWidth, qreal(0.1)); m_slSize->setValue(newWidth); } void KisBrushChooser::setImage(KisImageWSP image) { m_image = image; } #include "moc_kis_brush_chooser.cpp"