diff --git a/libs/ui/widgets/kis_pattern_chooser.cc b/libs/ui/widgets/kis_pattern_chooser.cc index f3b32f1466..d2a5ec64bc 100644 --- a/libs/ui/widgets/kis_pattern_chooser.cc +++ b/libs/ui/widgets/kis_pattern_chooser.cc @@ -1,120 +1,122 @@ /* * Copyright (c) 2004 Adrian Page * 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 "widgets/kis_pattern_chooser.h" #include #include #include #include #include #include #include #include #include #include #include "kis_signals_blocker.h" #include "kis_global.h" #include #include +#include + KisPatternChooser::KisPatternChooser(QWidget *parent) : QFrame(parent) { - m_lbName = new QLabel(this); + m_lblName = new KSqueezedTextLabel(this); + m_lblName->setTextElideMode(Qt::ElideLeft); KoResourceServer * rserver = KoResourceServerProvider::instance()->patternServer(); QSharedPointer adapter (new KoResourceServerAdapter(rserver)); m_itemChooser = new KoResourceItemChooser(adapter, this, true); m_itemChooser->setPreviewTiled(true); m_itemChooser->setPreviewOrientation(Qt::Horizontal); m_itemChooser->showTaggingBar(true); m_itemChooser->setSynced(true); connect(m_itemChooser, SIGNAL(resourceSelected(KoResource *)), this, SLOT(update(KoResource *))); connect(m_itemChooser, SIGNAL(resourceSelected(KoResource *)), this, SIGNAL(resourceSelected(KoResource *))); QVBoxLayout *mainLayout = new QVBoxLayout(this); - mainLayout->setObjectName("main layout"); + mainLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); mainLayout->setMargin(0); - mainLayout->addWidget(m_lbName); + mainLayout->addWidget(m_lblName); mainLayout->addWidget(m_itemChooser, 10); KisConfig cfg(true); m_itemChooser->configureKineticScrolling(cfg.kineticScrollingGesture(), cfg.kineticScrollingSensitivity(), cfg.kineticScrollingScrollbar()); setLayout(mainLayout); } KisPatternChooser::~KisPatternChooser() { } KoResource * KisPatternChooser::currentResource() { if (!m_itemChooser->currentResource()) { KoResourceServer * rserver = KoResourceServerProvider::instance()->patternServer(); if (rserver->resources().size() > 0) { KisSignalsBlocker blocker(m_itemChooser); m_itemChooser->setCurrentResource(rserver->resources().first()); } } return m_itemChooser->currentResource(); } void KisPatternChooser::setCurrentPattern(KoResource *resource) { m_itemChooser->setCurrentResource(resource); } void KisPatternChooser::setCurrentItem(int row, int column) { m_itemChooser->setCurrentItem(row, column); if (currentResource()) { update(currentResource()); } } void KisPatternChooser::setPreviewOrientation(Qt::Orientation orientation) { m_itemChooser->setPreviewOrientation(orientation); } void KisPatternChooser::update(KoResource * resource) { + m_lblName->setFixedWidth(m_itemChooser->width()); KoPattern *pattern = static_cast(resource); - - QString text = QString("%1 (%2 x %3)").arg(i18n(pattern->name().toUtf8().data())).arg(pattern->width()).arg(pattern->height()); - m_lbName->setText(text); + m_lblName->setText(QString("%1 (%2 x %3)").arg(i18n(pattern->name().toUtf8().data())).arg(pattern->width()).arg(pattern->height())); } void KisPatternChooser::setGrayscalePreview(bool grayscale) { m_itemChooser->setGrayscalePreview(grayscale); } diff --git a/libs/ui/widgets/kis_pattern_chooser.h b/libs/ui/widgets/kis_pattern_chooser.h index 637addc7fa..462df2a9f8 100644 --- a/libs/ui/widgets/kis_pattern_chooser.h +++ b/libs/ui/widgets/kis_pattern_chooser.h @@ -1,63 +1,63 @@ /* * Copyright (c) 2004 Adrian Page * * 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. */ #ifndef KIS_PATTERN_CHOOSER_H_ #define KIS_PATTERN_CHOOSER_H_ #include #include -class QLabel; +class KSqueezedTextLabel; class KoResourceItemChooser; class KoResource; class KRITAUI_EXPORT KisPatternChooser : public QFrame { Q_OBJECT public: KisPatternChooser(QWidget *parent = 0); ~KisPatternChooser() override; /// Gets the currently selected resource /// @returns the selected resource, 0 is no resource is selected KoResource *currentResource(); void setCurrentPattern(KoResource *resource); void setCurrentItem(int row, int column); void setGrayscalePreview(bool grayscale); /// determines whether the preview right or below the splitter void setPreviewOrientation(Qt::Orientation orientation); Q_SIGNALS: /// Emitted when a resource was selected void resourceSelected(KoResource *resource); void updateItemSize(); private Q_SLOTS: void update(KoResource *resource); private: - QLabel *m_lbName; + KSqueezedTextLabel *m_lblName; KoResourceItemChooser *m_itemChooser; }; #endif // KIS_PATTERN_CHOOSER_H_