summaryrefslogtreecommitdiffstats
path: root/src/knutmessage.cpp
blob: 95e250ad046afb127f7e2e00052c1ed97cc92313 (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
/***************************************************************************
                          knutmessage.cpp  -  description
                             -------------------
    begin                : So led 24 2004
    copyright            : (C) 2004 by Daniel Prynych
    email                : Daniel.Prynych@alo.cz
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "knutmessage.h"
#include <kglobal.h>
#include <kiconloader.h>

#include <layout.h>
#include <tqlabel.h>
#include <tqframe.h>
#include <tqpixmap.h>
#include <tqtimer.h>


KNutMessage::KNutMessage(const TQString messageText, const typeOfMessage type, const long int timeValidity, TQWidget *parent, const char *name) : KDialogBase(Plain, "Messages",Ok,Ok, parent, name, false, false) {


  setCaption("KNutClient");
  m_messageTimer = 0;
  KIconLoader *loader = KGlobal::iconLoader();

  switch(type) {
    case infoMess:
       m_ret = loader->loadIcon("messagebox_info", KIcon::NoGroup, KIcon::SizeMedium, KIcon::DefaultState, 0, true);
       break;
    case warningMess:
       m_ret = loader->loadIcon("messagebox_warning", KIcon::NoGroup, KIcon::SizeMedium, KIcon::DefaultState, 0, true);
       break;
    case criticalMess:
       m_ret = loader->loadIcon("messagebox_critical", KIcon::NoGroup, KIcon::SizeMedium, KIcon::DefaultState, 0, true);
       break;
    }

   TQFrame *page = plainPage();

   TQVBoxLayout *setTopLayout =     new TQVBoxLayout( page, 10, spacingHint(), "setTopLayout" );
   TQHBoxLayout *setMessageLayout = new TQHBoxLayout( setTopLayout, spacingHint(), "setMessageLayout" );

   TQLabel* picture = new TQLabel (page);
   TQLabel* text = new TQLabel (messageText,page);
   picture->setPixmap(m_ret);

   setMessageLayout->addWidget(picture);
   setMessageLayout->addWidget(text);

   if (timeValidity > 0 ) {
     m_messageTimer = new TQTimer(this);
     if (timeValidity > maxTime)
       m_messageTimer->start(maxTime*1000);
     else
       m_messageTimer->start(timeValidity*1000);
     connect (m_messageTimer,TQT_SIGNAL(timeout()),this,TQT_SLOT(timeout()));
     disableResize();
    }
  }

KNutMessage::~KNutMessage(){
  }

void KNutMessage::timeout(void) {

  if (m_messageTimer) m_messageTimer->stop();

  emit endMessage();
  }


void KNutMessage::slotOk (void) {

  if (m_messageTimer) m_messageTimer->stop();
  emit endMessage();
  }

void KNutMessage::moveEvent ( TQMoveEvent * e) {

  KDialogBase::moveEvent (e);
  emit messageMoved(x(),y());
}


#include "knutmessage.moc"