krita/ui

kis_statusbar.cc

Go to the documentation of this file.
00001 /* This file is part of KimageShop^WKrayon^WKrita
00002  *
00003  *  Copyright (c) 2006 Boudewijn Rempt <boud@valdyas.org>
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #include "kis_statusbar.h"
00021 
00022 
00023 #include <QLabel>
00024 #include <QFontMetrics>
00025 #include <QToolButton>
00026 
00027 #include <KoProgressBar.h>
00028 #include <ksqueezedtextlabel.h>
00029 #include <kstatusbar.h>
00030 #include <klocale.h>
00031 
00032 #include <KoColorProfile.h>
00033 #include <KoColorSpace.h>
00034 
00035 #include <kis_types.h>
00036 #include <kis_image.h>
00037 #include <kis_selection.h>
00038 #include <kis_paint_device.h>
00039 
00040 #include "kis_view2.h"
00041 #include "canvas/kis_canvas2.h"
00042 #include "kis_progress_widget.h"
00043 
00044 #include "KoViewConverter.h"
00045 
00046 enum {
00047     IMAGE_SIZE_ID,
00048     POINTER_POSITION_ID
00049 };
00050 
00051 KisStatusBar::KisStatusBar(KisView2 * view)
00052         : m_view(view)
00053 {
00054     m_selectionStatusLabel = new QLabel(view);
00055     m_selectionStatusLabel->setPixmap(KIcon("tool_rect_selection").pixmap(22));
00056     m_selectionStatusLabel->setEnabled(false);
00057     view->addStatusBarItem(m_selectionStatusLabel);
00058 
00059     // XXX: Use the KStatusbar fixed size labels!
00060     m_statusBarStatusLabel = new KSqueezedTextLabel(view);
00061     connect(KoToolManager::instance(), SIGNAL(changedStatusText(const QString &)),
00062             m_statusBarStatusLabel, SLOT(setText(const QString &)));
00063     view->addStatusBarItem(m_statusBarStatusLabel, 2);
00064 
00065     m_statusBarProfileLabel = new KSqueezedTextLabel(view);
00066     view->addStatusBarItem(m_statusBarProfileLabel, 3);
00067 
00068     m_imageSizeLabel = new QLabel(QString(), view);
00069     m_imageSizeLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
00070     m_imageSizeLabel->setMinimumWidth(100);
00071     view->addStatusBarItem(m_imageSizeLabel);
00072 
00073     m_pointerPositionLabel = new QLabel(QString(), view);
00074     m_pointerPositionLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
00075     m_pointerPositionLabel->setMinimumWidth(100);
00076     view->addStatusBarItem(m_pointerPositionLabel);
00077     m_pointerPositionLabel->setVisible(false);
00078 
00079     m_progress = new KisProgressWidget(view);
00080     m_progress->setMaximumWidth(225);
00081     m_progress->setMinimumWidth(225);
00082     view->addStatusBarItem(m_progress, 2, true);
00083 
00084     m_progress->hide();
00085 }
00086 
00087 KisStatusBar::~KisStatusBar()
00088 {
00089 }
00090 
00091 #define EPSILON 1e-6
00092 
00093 void KisStatusBar::setZoom(int zoom)
00094 {
00095     Q_UNUSED(zoom);
00096     /*
00097         if (zoom < 1 - EPSILON) {
00098             m_statusBarZoomLabel->setText(i18n("Zoom %1%",zoom * 100, 0, 'g', 4));
00099         } else {
00100             m_statusBarZoomLabel->setText(i18n("Zoom %1%",zoom * 100, 0, 'f', 0));
00101         }
00102     */
00103 }
00104 
00105 void KisStatusBar::documentMousePositionChanged(const QPointF &pos)
00106 {
00107     QPoint pixelPos = m_view->image()->documentToIntPixel(pos);
00108 
00109     pixelPos.setX(qBound(0, pixelPos.x(), m_view->image()->width() - 1));
00110     pixelPos.setY(qBound(0, pixelPos.y(), m_view->image()->height() - 1));
00111     m_pointerPositionLabel->setText(QString("%1, %2").arg(pixelPos.x()).arg(pixelPos.y()));
00112 }
00113 
00114 void KisStatusBar::imageSizeChanged(qint32 w, qint32 h)
00115 {
00116     m_imageSizeLabel->setText(QString("%1 x %2").arg(w).arg(h));
00117 }
00118 
00119 void KisStatusBar::setSelection(KisImageWSP image)
00120 {
00121     Q_UNUSED(image);
00122 
00123     KisSelectionSP selection = m_view->selection();
00124     if (selection && !selection->isDeselected()) {
00125         m_selectionStatusLabel->setEnabled(true);
00126 
00127         QRect r = selection->selectedExactRect();
00128         m_selectionStatusLabel->setToolTip(i18n("Selection Active: x = %1 y = %2 width = %3 height = %4", r.x(), r.y(), r.width(), r.height()));
00129         return;
00130     }
00131     m_selectionStatusLabel->setEnabled(false);
00132     m_selectionStatusLabel->setToolTip(i18n("No Selection"));
00133 }
00134 
00135 void KisStatusBar::setProfile(KisImageWSP image)
00136 {
00137     if (m_statusBarProfileLabel == 0) {
00138         return;
00139     }
00140 
00141     if (!image) return;
00142 
00143     if (image->profile() == 0) {
00144         m_statusBarProfileLabel->setText(i18n("No profile"));
00145     } else {
00146         m_statusBarProfileLabel->setText(image->colorSpace()->name() + "  " + image->profile()->name());
00147     }
00148 
00149 }
00150 
00151 void KisStatusBar::setHelp(const QString &t)
00152 {
00153     Q_UNUSED(t);
00154 }
00155 
00156 void KisStatusBar::updateStatusBarProfileLabel()
00157 {
00158     setProfile(m_view->image());
00159 }
00160 
00161 
00162 KisProgressWidget* KisStatusBar::progress()
00163 {
00164     return m_progress;
00165 }
00166 
00167 
00168 #include "kis_statusbar.moc"