summaryrefslogtreecommitdiff
path: root/src/ui/statusBar.h
blob: 9737f905a1ebb6abfcee9b83ee3bdbf2dede42fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/***************************************************************************
 *   fqterm, a terminal emulator for both BBS and *nix.                    *
 *   Copyright (C) 2008 fqterm development group.                          *
 *                                                                         *
 *   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 St, Fifth Floor, Boston, MA 02110-1301 USA.               *
 ***************************************************************************/

#ifndef FQTERM_STATUSBAR_H
#define FQTERM_STATUSBAR_H

#include "progressBar.h" //convenience
// #include <qwidget.h>     //baseclass
// #include <qmap.h>        //stack allocated
// #include <q3valuelist.h>  //stack allocated
//Added by qt3to4:
// #include <QCustomEvent>
#include <QLabel>
#include <QEvent>
#include <QPaintEvent>
#include <QMap>
#include <QList>
#include <QWidget>
#include <QProgressBar>

class QString;
class QLayout;
class QLabel;
class QString;

namespace FQTerm {

class PopupMessage;
typedef QMap < const QObject *, ProgressBar * > ProgressMap;

class StatusBar: public QWidget {
  Q_OBJECT;
 public:
  StatusBar(QWidget *parent_, const char *name = "mainStatusBar");
  static StatusBar *instance() {
    return singletonStatusBar_
        ;
  }
  /**
   * Start a progress operation, if owner is 0, the return value is
   * undefined - the application will probably crash.
   * @param owner controls progress for this operation
   * @return the progressBar so you can configure its parameters
   * @see setProgress( QObject*, int )
   * @see incrementProgress( QObject* )
   * @see setProgressStatus( const QObject*, const QString& )
   */
  ProgressBar &newProgressOperation(QObject *owner);

  void setProgress(const QObject *owner, int steps);
  void incrementProgress(const QObject *owner);
  void setProgressStatus(const QObject *owner, const QString &text);
 public slots:
  void setMainText(const QString &text);
  void resetMainText();
  void shortMessage(const QString &text);
  /** Stop anticipating progress from sender() */
  //void endProgressOperation();

  /** Stop anticipating progress from @param owner */
  void endProgressOperation(QObject *owner);

  /**
   * Convenience function works like setProgress( QObject*, int )
   * Uses the return value from sender() to determine the owner of
   * the progress bar in question
   */
  void setProgress(int steps);

  /**
   * Convenience function works like incrementProgress( QObject* )
   * Uses the return value from sender() to determine the owner of
   * the progress bar in question
   */
  void incrementProgress();

 public slots:
  void toggleProgressWindow(bool show);
  void abortAllProgressOperations();

 private slots:
  /** For internal use against KIO::Jobs */
  //void setProgress( KIO::Job*, unsigned long percent );
  void showMainProgressBar();
  void hideMainProgressBar();
  void updateProgressAppearance();

 protected:
  virtual void ensurePolished();
  // 		virtual void customEvent( QCustomEvent* );
  virtual void paintEvent(QPaintEvent*);
  virtual bool event(QEvent*);

  /**
   * You must parent the widget to the statusbar, we won't do that
   * for you! The widget will be added to the right of the layout.
   * Currently you must add widgets before the statusbar gets shown
   * for the first time, because we are not currently very flexible.
   */
  void addWidget(QWidget *widget);

  QLabel *m_mainTextLabel;
 private:
  void updateTotalProgress();
  bool allDone(); ///@return true if all progress operations are complete
  void pruneProgressBars(); /// deletes old progress bars

  QWidget *cancelButton() {
    return findChild<QWidget *>("cancelButton");
  }
  QWidget *toggleProgressWindowButton() {
    return findChild<QWidget *>("showAllProgressDetails");
  }
  QWidget *progressBox() {
    return findChild <QWidget *>("progressBox");
  }

  PopupMessage *popupProgressMessage_;
  QProgressBar *mainProgressBar_;

  ProgressMap progressMap_;
  //  QList<QWidget *> m_messageQueue;
  QString mainText_;

  QLayout *otherWidgetLayout_;
  static StatusBar *singletonStatusBar_;
};

}  // namespace FQTerm

#endif  // FQTERM_STATUSBAR_H