File indexing completed on 2024-04-14 14:36:06

0001 /* This file is part of the KDE Project
0002    Copyright (C) 2000 Klaas Freitag <freitag@suse.de>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef SIZEINDICATOR_H
0021 #define SIZEINDICATOR_H
0022 
0023 #include "kookascan_export.h"
0024 
0025 #include <qlabel.h>
0026 
0027 #define DEFAULT_SMALL       (1024)          // 1Kb
0028 #define DEFAULT_THRESHOLD   (1*1024*1024)       // 1Mb
0029 #define DEFAULT_CRITICAL    (4*1024*1024)       // 4Mb
0030 
0031 /**
0032  *  @short  small size indication widget for file sizes
0033  *  @author Klaas Freitag
0034  *
0035  *  the size indicator is a small widget that displays a file size in a small
0036  *  frame. The unit (currently kB and MB) is selected automagically.
0037  *  If the file size grows bigger than the threshold set in the constructor,
0038  *  the widget starts to change its background color to visualise to the
0039  *  user that he is doing something obvious.
0040  */
0041 
0042 class KOOKASCAN_EXPORT SizeIndicator : public QLabel
0043 {
0044     Q_OBJECT
0045 
0046 public:
0047     /**
0048      *  Creates a size indicator widget.
0049      *
0050      *  @param thresh Threshold size, above which the widget starts to turn the warning colour.
0051      *  @param crit Critical size, above which the widget starts to turn the error colour.
0052      */
0053     explicit SizeIndicator(QWidget *parent,
0054                   long thresh = DEFAULT_THRESHOLD,
0055                   long crit = DEFAULT_CRITICAL);
0056 
0057     ~SizeIndicator() override;
0058 
0059     /**
0060      * Sets the threshold size.
0061      *
0062      * @param thresh the threshold size.
0063      */
0064     void setThreshold(long thresh = DEFAULT_THRESHOLD);
0065 
0066     /**
0067      * Sets the critical size.
0068      *
0069      * @param crit the critical size.
0070      */
0071     void setCritical(long crit = DEFAULT_CRITICAL);
0072 
0073 public slots:
0074     /**
0075      * Sets the file size to display. The widget gets updated.
0076      *
0077      * @param newSize the size to set.
0078      */
0079     void setSizeInByte(long newSize);
0080 
0081 protected:
0082     void paintEvent(QPaintEvent *ev) override;
0083 
0084 private:
0085     long mThreshold;
0086     long mCritical;
0087     long mSizeInByte;
0088 
0089     class SizeIndicatorPrivate;
0090     SizeIndicatorPrivate *d;
0091 };
0092 
0093 #endif                          // SIZEINDICATOR_H