summaryrefslogtreecommitdiffstats
path: root/src/statusbar.cpp
blob: a21bacaec35cf699dfb7afd4136d90acbd2e7876 (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
/***************************************************************************
    copyright            : (C) 2005-2006 by Robby Stephenson
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of version 2 of the GNU General Public License as  *
 *   published by the Free Software Foundation;                            *
 *                                                                         *
 ***************************************************************************/

#include "statusbar.h"
#include "tellico_debug.h"
#include "progressmanager.h"
#include "tellico_debug.h"
#include "gui/progress.h"

#include <klocale.h>
#include <kapplication.h>
#include <kpushbutton.h>
#include <kiconloader.h>

#include <qobjectlist.h>
#include <qpainter.h>
#include <qstyle.h>
#include <qtimer.h>
#include <qtooltip.h>

using Tellico::StatusBar;
StatusBar* StatusBar::s_self = 0;

StatusBar::StatusBar(QWidget* parent_) : KStatusBar(parent_) {
  s_self = this;

  // don't care about text and id
  m_mainLabel = new KStatusBarLabel(QString(), 0, this);
  m_mainLabel->setIndent(4);
  m_mainLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
  addWidget(m_mainLabel, 3 /*stretch*/, true /*permanent*/);

  m_countLabel = new KStatusBarLabel(QString(), 1, this);
  m_countLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
  m_countLabel->setIndent(4);
  addWidget(m_countLabel, 0, true);

  m_progress = new GUI::Progress(100, this);
  addWidget(m_progress, 1, true);
  m_cancelButton = new KPushButton(SmallIcon(QString::fromLatin1("cancel")), QString::null, this);
  QToolTip::add(m_cancelButton, i18n("Cancel"));
  addWidget(m_cancelButton, 0, true);
  m_progress->hide();
  m_cancelButton->hide();

  ProgressManager* pm = ProgressManager::self();
  connect(pm, SIGNAL(signalTotalProgress(uint)), SLOT(slotProgress(uint)));
  connect(m_cancelButton, SIGNAL(clicked()), pm, SLOT(slotCancelAll()));
}

void StatusBar::polish() {
  KStatusBar::polish();

  int h = 0;
  QObjectList* list = queryList("QWidget", 0, false, false);
  for(QObject* o = list->first(); o; o = list->next()) {
    int _h = static_cast<QWidget*>(o)->minimumSizeHint().height();
    if(_h > h) {
      h = _h;
    }
  }

  h -= 4; // hint from amarok, it's too big usually

  for(QObject* o = list->first(); o; o = list->next()) {
    static_cast<QWidget*>(o)->setFixedHeight(h);
  }

  delete list;
}

void StatusBar::clearStatus() {
  setStatus(i18n("Ready."));
}

void StatusBar::setStatus(const QString& status_) {
  // always add a space for asthetics
  m_mainLabel->setText(status_ + ' ');
}

void StatusBar::setCount(const QString& count_) {
  m_countLabel->setText(count_ + ' ');
}

void StatusBar::slotProgress(uint progress_) {
  m_progress->setProgress(progress_);
  if(m_progress->isDone()) {
    m_progress->hide();
    m_cancelButton->hide();
  } else if(m_progress->isHidden()) {
    m_progress->show();
    if(ProgressManager::self()->anyCanBeCancelled()) {
      m_cancelButton->show();
    }
    kapp->processEvents(); // needed so the window gets updated ???
  }
}

void StatusBar::slotUpdate() {
/*
  myDebug() << "StatusBar::slotUpdate() - " << m_progress->isShown() << endl;
  if(m_progressBox->isEmpty()) {
    QTimer::singleShot(0, m_progress, SLOT(hide()));
//    m_progressBox->hide();
  } else {
    QTimer::singleShot(0, m_progress, SLOT(show()));
//    m_progressBox->show();
  }
*/
}

#include "statusbar.moc"