File indexing completed on 2024-04-28 08:11:07
0001 /************************************************************************ 0002 * * 0003 * This file is part of Kooka, a scanning/OCR application using * 0004 * Qt <http://www.qt.io> and KDE Frameworks <http://www.kde.org>. * 0005 * * 0006 * Copyright (C) 2013-2016 Jonathan Marten <jjm@keelhaul.me.uk> * 0007 * * 0008 * Kooka is free software; you can redistribute it and/or modify it * 0009 * under the terms of the GNU Library General Public License as * 0010 * published by the Free Software Foundation and appearing in the * 0011 * file COPYING included in the packaging of this file; either * 0012 * version 2 of the License, or (at your option) any later version. * 0013 * * 0014 * As a special exception, permission is given to link this program * 0015 * with any version of the KADMOS OCR/ICR engine (a product of * 0016 * reRecognition GmbH, Kreuzlingen), and distribute the resulting * 0017 * executable without including the source code for KADMOS in the * 0018 * source distribution. * 0019 * * 0020 * This program is distributed in the hope that it will be useful, * 0021 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0023 * GNU General Public License for more details. * 0024 * * 0025 * You should have received a copy of the GNU General Public * 0026 * License along with this program; see the file COPYING. If * 0027 * not, see <http://www.gnu.org/licenses/>. * 0028 * * 0029 ************************************************************************/ 0030 0031 #include "statusbarmanager.h" 0032 0033 #include <qstatusbar.h> 0034 #include <qlabel.h> 0035 #include <qstyle.h> 0036 0037 #include <klocalizedstring.h> 0038 #include <kxmlguiwindow.h> 0039 0040 #include "imagecanvas.h" 0041 #include "previewer.h" 0042 #include "sizeindicator.h" 0043 0044 0045 StatusBarManager::StatusBarManager(KXmlGuiWindow *mainWindow) 0046 : QObject(mainWindow) 0047 { 0048 mStatusBar = mainWindow->statusBar(); 0049 mMargin = 2*mStatusBar->style()->pixelMetric(QStyle::PM_LayoutLeftMargin); 0050 0051 // Messages 0052 mMessageLabel = new QLabel(i18nc("@info:status", "Ready")); 0053 mStatusBar->addWidget(mMessageLabel, 1); 0054 0055 // Image dimensions 0056 QString s = ImageCanvas::imageInfoString(2000, 2000, 48); 0057 mImageDimsLabel = new QLabel(s); 0058 mImageDimsLabel->setAlignment(Qt::AlignHCenter); 0059 mImageDimsLabel->setToolTip(i18nc("@info:tooltip", "The size of the image being viewed in the gallery")); 0060 mImageDimsLabel->setMinimumWidth(mImageDimsLabel->sizeHint().width()+mMargin); 0061 mStatusBar->addPermanentWidget(mImageDimsLabel); 0062 0063 // Preview dimensions 0064 s = Previewer::previewInfoString(500.0, 500.0, 1200, 1200); 0065 mPreviewDimsLabel = new QLabel(s); 0066 mPreviewDimsLabel->setAlignment(Qt::AlignHCenter); 0067 mPreviewDimsLabel->setToolTip(i18nc("@info:tooltip", "The size of the selected area that will be scanned")); 0068 mPreviewDimsLabel->setMinimumWidth(mPreviewDimsLabel->sizeHint().width()+mMargin); 0069 mStatusBar->addPermanentWidget(mPreviewDimsLabel); 0070 0071 // Preview file size 0072 mFileSize = new SizeIndicator(nullptr); 0073 mFileSize->setMaximumWidth(100); 0074 mFileSize->setFrameStyle(QFrame::NoFrame); 0075 mFileSize->setToolTip(i18nc("@info:tooltip", "<qt>This is the uncompressed size of the scanned image. " 0076 "It tries to warn you if you try to produce too big an image by " 0077 "changing its background color.")); 0078 mStatusBar->addPermanentWidget(mFileSize); 0079 0080 mStatusBar->setSizeGripEnabled(false); 0081 mStatusBar->show(); 0082 } 0083 0084 0085 // In this application, the length of some of the status bar strings 0086 // (e.g. the image/preview dimensions) can vary greatly. To avoid the 0087 // status bar items annoyingly jumping around when this happens, once one 0088 // of those items has reached a certain size it is not allowed to shrink 0089 // again to less than that. 0090 void StatusBarManager::setLabelText(QLabel *l, const QString &text) 0091 { 0092 const int oldWidth = l->width(); 0093 l->setText(text); 0094 const int newWidth = l->sizeHint().width(); 0095 if (newWidth>oldWidth) l->setMinimumWidth(newWidth+mMargin); 0096 } 0097 0098 0099 void StatusBarManager::setStatus(const QString &text, StatusBarManager::Item item) 0100 { 0101 switch (item) 0102 { 0103 case StatusBarManager::Message: 0104 mMessageLabel->setText(text); 0105 break; 0106 0107 case StatusBarManager::ImageDims: 0108 setLabelText(mImageDimsLabel, i18nc("@info:status", "Image: %1", text)); 0109 break; 0110 0111 case StatusBarManager::PreviewDims: 0112 setLabelText(mPreviewDimsLabel, i18nc("@info:status", "Scan: %1", text)); 0113 break; 0114 0115 default: 0116 break; 0117 } 0118 } 0119 0120 0121 void StatusBarManager::clearStatus(StatusBarManager::Item item) 0122 { 0123 setStatus(QString(), item); 0124 } 0125 0126 0127 void StatusBarManager::setFileSize(long size) 0128 { 0129 mFileSize->setSizeInByte(size); 0130 }