File: rinfowidget.cpp

package info (click to toggle)
qcad 1.3.3-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,504 kB
  • ctags: 2,449
  • sloc: cpp: 29,400; makefile: 49; sh: 15
file content (225 lines) | stat: -rw-r--r-- 5,178 bytes parent folder | download
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/***************************************************************************
                          rinfowidget.cpp  -  description
                             -------------------
    begin                : Mon Sep 27 1999
    copyright            : (C) 1999 by Andreas Mustun
    email                : andrew@ribbonsoft.com
 ***************************************************************************/


/****************************************************************************
** rinfowidget.cpp 1998/09/23 A. Mustun RibbonSoft
**
** Copyright (C) 1998 RibbonSoft.  All rights reserved.
**
        Last change:  A    10 Dec 1998   10:06 am
*****************************************************************************/

#include "rinfowidget.h"

#include <qdatetime.h>
#include <qfileinfo.h>
#include <qtooltip.h>

#include "rgraphic.h"
#include "rconfig.h"
#include "rlabel.h"
#include "rlog.h"

// Constructor:
//
RInfoWidget::RInfoWidget(QWidget* _parent, 
                         const char* _name, 
                         WFlags _f)
:RWidget(_parent, _name, _f)
{
  graphic=0;

  valid=false;

  //setFrameStyle(WinPanel|Raised);
  //setFrameStyle(Panel|Sunken);
  setFrameStyle(WinPanel|Sunken);
  setLineWidth(1);

  lPath = new RLabel(RMES(179), this, "lpath");
  QToolTip::add(lPath, RMES(180));
  path  = new RLabel("", this, "path");

  lCreation = new RLabel(RMES(181), this, "lcreation");
  QToolTip::add(lCreation, RMES(182));
  creation  = new RLabel("", this, "creation");

  lSize = new RLabel(RMES(183), this, "lsize");
  QToolTip::add(lSize, RMES(184));
  size  = new RLabel("", this, "size");

  lObjects = new RLabel(RMES(185), this, "lobjects");
  QToolTip::add(lObjects, RMES(186));
  objects  = new RLabel("", this, "objects");

  lTotalWay = new RLabel(RMES(187), this, "ltotalway");
  QToolTip::add(lTotalWay, RMES(188));
  totalWay  = new RLabel("", this, "totalway");

  lCuttingWay = new RLabel(RMES(189), this, "lcuttingway");
  QToolTip::add(lCuttingWay, RMES(190));
  cuttingWay  = new RLabel("", this, "cuttingway");
                             
}



// Destructor:
//
RInfoWidget::~RInfoWidget()
{

}



// Show info widget:
//
void 
RInfoWidget::show()
{
  RWidget::show();
  
  if(!valid) updateInfo();
}



// Resize event:
//
void 
RInfoWidget::resizeEvent(QResizeEvent* _ev)
{
  RWidget::resizeEvent(_ev);
  resizeChildren();
}



// Resize the children:
//
void
RInfoWidget::resizeChildren()
{
  int y=5;
  
  if(lPath)       lPath->setGeometry(10, y, 65, 14);
  if(path)        path-> setGeometry(105, y, width()-115, 14);
  y+=16;
  if(lCreation)   lCreation->setGeometry(10, y, 65, 14);
  if(creation)    creation-> setGeometry(105, y, width()-115, 14);
  y+=16;
  if(lSize)       lSize->setGeometry(10, y, 65, 14);
  if(size)        size-> setGeometry(105, y, width()-115, 14);
  y+=16;
  if(lObjects)    lObjects->setGeometry(10, y, 65, 14);
  if(objects)     objects-> setGeometry(105, y, width()-115, 14);
  y+=16;
  if(lTotalWay)   lTotalWay->setGeometry(10, y, 65, 14);
  if(totalWay)    totalWay-> setGeometry(105, y, width()-115, 14);
  y+=16;
  if(lCuttingWay) lCuttingWay->setGeometry(10, y, 65, 14);
  if(cuttingWay)  cuttingWay-> setGeometry(105, y, width()-115, 14);

  updateInfo(false);
  
}



// Set the pointer to a graphic and update the layers:
//
void 
RInfoWidget::setGraphic(RGraphic* _graphic) 
{ 
  graphic=_graphic;
  valid=false;
  if(graphic) updateInfo();
}



// Update the graphic info:
//   only if the info widget is visible
//
// _values: true:  update also values
//          false: update only layout
//
void 
RInfoWidget::updateInfo(bool _values)
{
  // Update only if visible:
  //
  if(isVisible() && graphic) {
    
    QFileInfo fi(graphic->getFileName().data());
    QDate     fd(fi.lastModified().date());
    QTime     ft(fi.lastModified().time());
    QCString   str;
    
    if(path) {
      if(fi.exists()) {
        str=fi.absFilePath();
        path->setText(str);
        while(str.length()>3 && path->sizeHint().width()>path->width()) {
          str.remove(0, 1);
          str[0]='.';
          str[1]='.';
          path->setText(str);
        }
      }
      else {
        path->setText("-");
      }
    }
    if(creation && _values) {
      if(fi.exists()) {
        str.sprintf("%s / %s", 
                    fd.toString().data(), ft.toString().data());
        creation->setText(str.data());
      }
      else {
        creation->setText("-");
      }
    }
    if(size && _values) {
      if(fi.exists()) {
        str.sprintf("%d Bytes", fi.size());
        size->setText(str.data());
      }
      else {
        size->setText("-");
      }
    }
    if(objects && _values) {
      str.sprintf("%d", graphic->count());
      objects->setText(str.data());
    }
    if(totalWay && _values) {
      str.sprintf("%.3f mm", graphic->getTotalWay());
      totalWay->setText(str.data());
    }
    if(cuttingWay && _values) {
      str.sprintf("%.3f mm", graphic->getCuttingWay());
      cuttingWay->setText(str.data());
    }

    repaint();
    if(_values) valid=true;
  }

  // It's not visible / update later:
  //
  else {
    valid=false;
  }
}

// EOF