summaryrefslogtreecommitdiffstats
path: root/quanta/components/csseditor/csseditor.cpp
blob: 5393d8755a9cc31e7e9bd83528c626c9db6cf221 (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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
/***************************************************************************
                          csseditor.cpp  -  description
                             -------------------
    begin                : mer lug 23 11:20:17 CEST 2003
    copyright            : (C) 2003 by gulmini luciano
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 "csseditor.h"
#include <tqlayout.h>
#include <tqtabwidget.h>
#include <tqpushbutton.h>
#include <tqcheckbox.h>
#include <tqtextedit.h>
#include <tqtextstream.h>
#include <tqfileinfo.h>

#include <kapplication.h>
#include <klocale.h>
#include <khtml_part.h>
#include <khtmlview.h>
#include <kstandarddirs.h>
#include <klineedit.h>
#include <kdebug.h>
#include <kconfig.h>
#include <kparts/browserextension.h>

#include "propertysetter.h"
#include "qmyhighlighter.h"
#include "cssshpropertyparser.h"
#include "shorthandformer.h"
#include "percentageeditor.h"
#include "colorslider.h"
#include "tlpeditors.h"
#include "doubleeditors.h"
#include "specialsb.h"
#include "colorrequester.h"



myCheckListItem::myCheckListItem(TQListView * parent, const TQString & text):TQCheckListItem(parent, text, TQCheckListItem::CheckBox),m_checkedChildren(0){
  m_sig = new TQSignal;
}

myCheckListItem::myCheckListItem(TQCheckListItem * parent, const TQString & text):TQCheckListItem(parent, text, TQCheckListItem::CheckBox),m_checkedChildren(0){
  m_sig = new TQSignal;
}

myCheckListItem::~myCheckListItem(){
  delete m_sig;
}

void myCheckListItem::connect( TQObject *receiver, const char *member ){
  m_sig->connect( receiver, member );
}

void myCheckListItem::activate(){
  if(isOn()) TQCheckListItem::activate();
}

void myCheckListItem::addCheckedChild() {
  m_checkedChildren++;
}

void myCheckListItem::stateChange (bool b){

   if(!b) {
     if(childCount()) {
       TQListViewItem * child = firstChild();
       while( child ) {
         m_sig->setValue(TQVariant(child->text(0)));
         m_sig->activate();
         static_cast<myCheckListItem*>(child)->setOn(false);
         child = child->nextSibling();
       }
       m_checkedChildren = 0;
     }
     else {
       if(parent()){
         myCheckListItem *p = static_cast<myCheckListItem*>(parent());
         while( p ) {
           if( p->m_checkedChildren != 1) {
             p->m_checkedChildren--;
             m_sig->setValue(TQVariant(text(0)));
             m_sig->activate();
             break;
           }
           else {
             m_sig->setValue(TQVariant(text(0)));
             m_sig->activate();
             p->setOn(false);
           }
           p = static_cast<myCheckListItem*>(p->parent());
         }
       }
       else {
         m_sig->setValue(TQVariant(text(0)));
         m_sig->activate();
       }
     }
   }
    else {
      if(parent()) static_cast<myCheckListItem*>(parent())->addCheckedChild();
    }
}

void CSSEditor::appendSub(TQDomNodeList l, myCheckListItem *cli){
  unsigned int i;
  for(i=0;i<l.length();i++) {
    myCheckListItem *item  = new myCheckListItem(cli,l.item(i).toElement().tagName());
    item->connect(this,TQT_SLOT(removeProperty(const TQVariant&)));
    if(l.item(i).toElement().attribute("hasSub") == "yes")
      appendSub(l.item(i).childNodes(),item);
  }
}

void CSSEditor::buildListView(TQDomNodeList l, TQListView *lv){
  unsigned int i;
  for(i=0;i<l.length();i++) {
    myCheckListItem *item = new myCheckListItem(lv,l.item(i).toElement().tagName());
    item->connect(this,TQT_SLOT(removeProperty(const TQVariant&)));
    if(l.item(i).toElement().attribute("hasSub") == "yes") {
      TQDomNodeList listSub = l.item(i).childNodes();
      appendSub(listSub,item);
    }
  }
}

void CSSEditor::setCurrentPropOn(const TQString& s){
 if( (m_currentProp = static_cast<myCheckListItem*>(lvVisual->findItem( s,0 )) ))
    m_currentProp->setOn(true);
  else
  if( (m_currentProp = static_cast<myCheckListItem*>(lvAll->findItem( s,0 )) ))
    m_currentProp->setOn(true);
  else
  if( (m_currentProp = static_cast<myCheckListItem*>(lvAural->findItem( s,0 )) ))
    m_currentProp->setOn(true);
  else
  if( (m_currentProp = static_cast<myCheckListItem*>(lvInteractive->findItem( s,0 )) ))
    m_currentProp->setOn(true);
  else
  if( (m_currentProp = static_cast<myCheckListItem*>(lvPaged->findItem( s,0 )) ))
    m_currentProp->setOn(true);

  if( m_currentProp && m_currentProp->depth() ) {
    myCheckListItem *p = static_cast<myCheckListItem*>(m_currentProp->parent());
    while(p) {
      p->setOn(true);
      p=static_cast<myCheckListItem*>(p->parent());
    }
  }
}


 void CSSEditor::addAndSetPropertyOn(const TQString& property, const TQString& value){
   addProperty(property,value);
   setCurrentPropOn(property);
 }

 void CSSEditor::setSidesOfPropertyBorderOn(const TQString& s){
   static_cast<myCheckListItem*>(lvVisual->findItem( "border-top",0 ))->setOn(true);
   static_cast<myCheckListItem*>(lvVisual->findItem( "border-right",0 ))->setOn(true);
   static_cast<myCheckListItem*>(lvVisual->findItem( "border-bottom",0 ))->setOn(true);
   static_cast<myCheckListItem*>(lvVisual->findItem( "border-left",0 ))->setOn(true);
   static_cast<myCheckListItem*>(lvVisual->findItem( "border-top-"+s,0 ))->setOn(true);
   static_cast<myCheckListItem*>(lvVisual->findItem( "border-right-"+s,0 ))->setOn(true);
   static_cast<myCheckListItem*>(lvVisual->findItem( "border-bottom-"+s,0 ))->setOn(true);
   static_cast<myCheckListItem*>(lvVisual->findItem( "border-left-"+s,0 ))->setOn(true);
 }

void CSSEditor::hidePreviewer(){
  fPreview->hide();
 }

void CSSEditor::initialize(){

  m_config = kapp->config();     
  connect(pbOk, TQT_SIGNAL(clicked()), this, TQT_SLOT(toggleShortendForm()));
  m_config->setGroup("CSSEditor Options");
  SHckb->setChecked(m_config->readBoolEntry("Shorthand form enabled",false));

  TQString configFile = locate("appdata", "csseditor/config.xml");

  m_myhi = new QMyHighlighter(display);

  TQBoxLayout *fPreviewLayout = new TQBoxLayout(fPreview,TQBoxLayout::LeftToRight);
  m_previewer=new KHTMLPart(fPreview);

  fPreviewLayout->addWidget(m_previewer->view());

  TQFile file( configFile );
  if ( !file.open( IO_ReadOnly ) ) {
    return;
  }
  if ( !m_doc.setContent( &file ) ) {
    file.close();
    return;
  }
  file.close();

  TQDomElement docElem = m_doc.documentElement();

  TQDomNode n = docElem.firstChild();
  while( !n.isNull() ) {
    TQDomElement e = n.toElement();
    if( !e.isNull() ) {
      if( e.attribute("type") == "visual") {
        lvVisual->setRootIsDecorated(true);
        buildListView(e.childNodes(), lvVisual);
      }
      if( e.attribute("type") == "paged") {
        lvPaged->setRootIsDecorated(true);
        buildListView(e.childNodes(), lvPaged);
      }
      if( e.attribute("type") == "interactive") {
        lvInteractive->setRootIsDecorated(true);
        buildListView(e.childNodes(), lvInteractive);
      }
      if( e.attribute("type") == "aural") {
        lvAural->setRootIsDecorated(true);
        buildListView(e.childNodes(), lvAural);
      }
      if( e.attribute("type") == "all"){
        lvAll->setRootIsDecorated(true);
        buildListView(e.childNodes(), lvAll);
      }
    }
    n = n.nextSibling();
  } // end while

  Connect();

  TQBoxLayout *fEditingLayout = new TQBoxLayout(fEditing,TQBoxLayout::LeftToRight);

  m_ps = new propertySetter(fEditing);
  fEditingLayout->addWidget(m_ps);
  connect(m_ps, TQT_SIGNAL(valueChanged(const TQString&)), this, TQT_SLOT(checkProperty(const TQString&)));

  TQStringList props;
  TQString temp;
  bool normalMode = true;

  if( !m_selectorName.isEmpty() ){ //the cssselector has been called
     m_initialProperties = m_initialProperties.stripWhiteSpace();
     props=TQStringList::split(";",m_initialProperties);
     temp= m_selectorName + " {\n\t" ;
   }

  else {
    m_InlineStyleContent = m_InlineStyleContent.stripWhiteSpace();
    normalMode = false;
    props=TQStringList::split(";",m_InlineStyleContent);
    temp="\n\t";
  }

  for ( TQStringList::Iterator it = props.begin(); it != props.end(); ++it ) {
       const TQString propertyName((*it).section(":",0,0).stripWhiteSpace());
       const TQString propertyValue((*it).section(":",1));

      if( ShorthandFormer::SHFormList().contains(propertyName)==0 ) {
         temp+= propertyName + " : " + propertyValue +";\n\t";
         addAndSetPropertyOn(propertyName,propertyValue);
      }
    else{
      ShorthandFormer decompressor;
      TQMap<TQString,TQString> expandedProperties = decompressor.expand(propertyName, propertyValue );
      TQMap<TQString,TQString>::Iterator it;

        for ( it = expandedProperties.begin(); it != expandedProperties.end(); ++it ) {
          addAndSetPropertyOn( it.key(), it.data() );
          temp += ( it.key() + " : " + it.data() + ";\n\t");
        }
    }
    }
    temp.truncate(temp.length()-1);
    //temp.chop(1);
    if(normalMode)//normal mode editing
      temp+="}";
    display->setText(temp);
    activatePreview();
}

void CSSEditor::toggleShortendForm()
{
 m_config->setGroup("CSSEditor Options");
 m_config->writeEntry("Shorthand form enabled", SHckb->isChecked());
 m_config->sync();
}

CSSEditor::CSSEditor(TQListViewItem *i, TQWidget *parent, const char *name) : CSSEditorS(parent, name){
  m_selectorName = i->text(0);
  m_initialProperties = i->text(1);
}

CSSEditor::~CSSEditor() {
    delete m_myhi;
    delete m_ps;
    delete m_previewer;
}

void CSSEditor::setMiniEditors(TQListViewItem* i){

  m_ps->reset();

  if(i->childCount()==0) {
    m_currentProp = static_cast<myCheckListItem*>(i);
    TQDomNodeList valueTypes = m_doc.elementsByTagName(i->text(0)).item(0).childNodes();
    unsigned int i;
    for(i=0; i<valueTypes.length(); i++) {
      TQDomElement curr =valueTypes.item(i).toElement();
      TQString valueTypeName(curr.tagName());

      if(valueTypeName =="list") {
        m_ps->setComboBox();
        TQStringList values = TQStringList::split(",",curr.attribute("value"));
        m_ps->ComboBox()->insertStringList(values);
        if(m_properties.contains(m_currentProp->text(0)) !=0 )
          if( values.contains(m_currentProp->text(0)))
            m_ps->ComboBox()->setCurrentText(m_properties[m_currentProp->text(0)]);
        if(curr.attribute("editable") == "yes"){
          m_ps->ComboBox()->setEditable(true);
          /*if(m_properties.contains(m_currentProp->text(0)) !=0 )
            m_ps->ComboBox()->setEditText(m_properties[m_currentProp->text(0)]); */
        }
      }
      else

      /*if( typeName == "spinbox") {
            m_ps->setSpinBox("0", values.item(k).toElement().attribute("minValue"),
            values.item(k).toElement().attribute("maxValue"),
            values.item(k).toElement().attribute("suffix"));
          }

      else*/
      if( valueTypeName == "number") m_ps->setLineEdit();
      else
      if( valueTypeName == "integer") {
        if(m_properties.contains(m_currentProp->text(0)) !=0 ) {
          if(!curr.attribute("minValue").isNull())
            m_ps->setSpinBox(m_properties[m_currentProp->text(0)],curr.attribute("minValue"));
          else
            m_ps->setSpinBox(m_properties[m_currentProp->text(0)]);
        }
        else
          if(!curr.attribute("minValue").isNull())
            m_ps->setSpinBox("0",curr.attribute("minValue"));
          else
            m_ps->setSpinBox();
      }
      else
      if( valueTypeName == "length") {
        lengthEditor *editor = new lengthEditor(m_ps);
        if(m_properties.contains(m_currentProp->text(0)) !=0 )
          editor->setInitialValue(m_properties[m_currentProp->text(0)]);
        else
          editor->setInitialValue(TQString::null);
        m_ps->installMiniEditor(editor);
      }
      else
      if( valueTypeName == "percentage") {
        if(m_properties.contains(m_currentProp->text(0)) !=0 ){
          percentageEditor *editor = new percentageEditor(m_properties[m_currentProp->text(0)],m_ps);
          m_ps->installMiniEditor(editor);
        }
        else {
          percentageEditor *editor = new percentageEditor("0",m_ps);
          m_ps->installMiniEditor(editor);
        }
      }
      else
      if( valueTypeName == "doubleLength") {
        doubleLengthEditor *editor = new doubleLengthEditor(m_ps);

        if(m_properties.contains(m_currentProp->text(0)) !=0 ){
          TQString temp(m_properties[m_currentProp->text(0)].simplifyWhiteSpace()),
                       sx(temp.section(" ",0,0)),
                       dx(temp.section(" ",1,1));

          editor->setInitialValue(sx,dx);
        }
        else editor->setInitialValue(TQString::null,TQString::null);
        m_ps->installMiniEditor(editor);
      }
      else
      if( valueTypeName == "doublePercentage") {
        doublePercentageEditor *editor = new doublePercentageEditor(m_ps);

        if(m_properties.contains(m_currentProp->text(0)) !=0 ){
          TQString temp(m_properties[m_currentProp->text(0)].simplifyWhiteSpace()),
                       sx(temp.section(" ",0,0)),
                       dx(temp.section(" ",1,1));

          editor->setInitialValue(sx,dx);
        }
        else editor->setInitialValue(TQString::null,TQString::null);
        m_ps->installMiniEditor(editor);
      }
      else
      if( valueTypeName == "frequency") {
        frequencyEditor *editor = new frequencyEditor(m_ps);
        if(m_properties.contains(m_currentProp->text(0)) !=0 )
          editor->setInitialValue(m_properties[m_currentProp->text(0)]);
        else
          editor->setInitialValue(TQString::null);
        m_ps->installMiniEditor(editor);
      }
      else
      if( valueTypeName == "time") {
        timeEditor *editor = new timeEditor(m_ps);
        if(m_properties.contains(m_currentProp->text(0)) !=0 )
          editor->setInitialValue(m_properties[m_currentProp->text(0)]);
        else
          editor->setInitialValue(TQString::null);
        m_ps->installMiniEditor(editor);
      }
      else
      if( valueTypeName == "angle") {
        angleEditor *editor = new angleEditor(m_ps);
        if(m_properties.contains(m_currentProp->text(0)) !=0 )
         editor->setInitialValue(m_properties[m_currentProp->text(0)]);
        else
          editor->setInitialValue(TQString::null);
        m_ps->installMiniEditor(editor);
      }
      else
      if( valueTypeName == "freeedit") {
        m_ps->setLineEdit();
      }
      else
      if( valueTypeName == "uri") {
        URIEditor *editor = new URIEditor(m_ps);

        if(curr.attribute("mode") == "multi") editor->setMode(URIEditor::Multi);
        else editor->setMode(URIEditor::Single);

        if( curr.attribute("resourceType") == "audio") editor->setResourceType(URIEditor::audio);
        else
          if( curr.attribute("resourceType") == "image") editor->setResourceType(URIEditor::image);
          else
            if( curr.attribute("resourceType") == "mousePointer") editor->setResourceType(URIEditor::mousePointer);

        m_ps->installMiniEditor(editor);
      }
      else
      if( valueTypeName == "colors") {
        RGBcolorSlider *RGBeditor = new RGBcolorSlider(m_ps);
        colorRequester *CReditor = new colorRequester(m_ps);
        if(m_properties.contains(m_currentProp->text(0)) !=0 ){
          CReditor->lineEdit()->setText(m_properties[m_currentProp->text(0)]);
          CReditor->setInitialValue();

        }

        m_ps->installMiniEditor(CReditor);
        m_ps->setPredefinedColorListEditor();
        m_ps->installMiniEditor(RGBeditor);
      }
      else
      if( valueTypeName =="doubleList") {
        doubleComboBoxEditor *editor = new doubleComboBoxEditor(m_ps);
        editor->cbSx()->insertStringList(TQStringList::split(",",curr.firstChild().toElement().attribute("value")));
        editor->cbDx()->insertStringList(TQStringList::split(",",curr.lastChild().toElement().attribute("value")));
        m_ps->installMiniEditor(editor);
      }
      else
        if( valueTypeName == "fontDialog" ){
          fontEditor *editor = new fontEditor(m_ps);
          if(m_properties.contains(m_currentProp->text(0)) !=0 ){
            editor->setInitialValue(m_properties[m_currentProp->text(0)]);
          }
          else editor->setInitialValue(TQString::null);
          m_ps->installMiniEditor(editor);
        }
    }
    m_ps->addButton();
    m_ps->Show();
  }
}

void CSSEditor::checkProperty(const TQString& v){
  if(!m_currentProp->isOn())
    m_currentProp->setOn(true);

  if( m_currentProp->depth() ){
    myCheckListItem *p = static_cast<myCheckListItem*>(m_currentProp->parent());
    while(p){
      p->setOn(true);
      p=static_cast<myCheckListItem*>(p->parent());
    }
  }

  if(m_currentProp->text(0) =="border-style" ){
    setSidesOfPropertyBorderOn("style");
    TQStringList values = TQStringList::split(" ",v.stripWhiteSpace());
    addProperty("border-top-style",values[0]);
    switch(values.count()) {
      case 1:
                   addProperty("border-right-style",values[0]);
                   addProperty("border-bottom-style",values[0]);
                   addProperty("border-left-style",values[0]);
                   break;

      case 2:
                   addProperty("border-right-style",values[1]);
                   addProperty("border-bottom-style",values[0]);
                   addProperty("border-left-style",values[1]);
                   break;

      case 3:
                   addProperty("border-right-style",values[1]);
                   addProperty("border-bottom-style",values[2]);
                   addProperty("border-left-style",values[1]);
                   break;

      case 4:
                   addProperty("border-right-style",values[1]);
                   addProperty("border-bottom-style",values[2]);
                   addProperty("border-left-style",values[3]);break;
    }
  }
  else
  if(m_currentProp->text(0) =="border-width" ){
    setSidesOfPropertyBorderOn("width");
    TQStringList values = TQStringList::split(" ",v.stripWhiteSpace());
    addProperty("border-top-width",values[0]);
    switch(values.count()) {
      case 1:
                   addProperty("border-right-width",values[0]);
                   addProperty("border-bottom-width",values[0]);
                   addProperty("border-left-width",values[0]);
                   break;

      case 2:
                   addProperty("border-right-width",values[1]);
                   addProperty("border-bottom-width",values[0]);
                   addProperty("border-left-width",values[1]);
                   break;

      case 3:
                   addProperty("border-right-width",values[1]);
                   addProperty("border-bottom-width",values[2]);
                   addProperty("border-left-width",values[1]);
                   break;

      case 4:
                   addProperty("border-right-width",values[1]);
                   addProperty("border-bottom-width",values[2]);
                   addProperty("border-left-width",values[3]);break;
    }
  }
  else
  if(m_currentProp->text(0) =="border-color" ){
    setSidesOfPropertyBorderOn("color");
    TQStringList values = TQStringList::split(" ",v.stripWhiteSpace());
    addProperty("border-top-color",values[0]);
    switch(values.count()) {
      case 1:
                   addProperty("border-right-color",values[0]);
                   addProperty("border-bottom-color",values[0]);
                   addProperty("border-left-color",values[0]);
                   break;

      case 2:
                   addProperty("border-right-color",values[1]);
                   addProperty("border-bottom-color",values[0]);
                   addProperty("border-left-color",values[1]);
                   break;

      case 3:
                   addProperty("border-right-color",values[1]);
                   addProperty("border-bottom-color",values[2]);
                   addProperty("border-left-color",values[1]);
                   break;

      case 4:
                   addProperty("border-right-style",values[1]);
                   addProperty("border-bottom-style",values[2]);
                   addProperty("border-left-style",values[3]);break;
    }
  }
  else addProperty(m_currentProp->text(0),v);
  emit signalUpdatePreview();
}

void CSSEditor::Connect(){
  connect(this, TQT_SIGNAL(signalUpdatePreview()), this, TQT_SLOT(updatePreview()));
  connect(lvVisual,TQT_SIGNAL(selectionChanged ( TQListViewItem *  )),this,TQT_SLOT(setMiniEditors ( TQListViewItem *  )));
  connect(lvAll,TQT_SIGNAL( selectionChanged( TQListViewItem *  )),this,TQT_SLOT(setMiniEditors ( TQListViewItem *  )));
  connect(lvAural,TQT_SIGNAL( selectionChanged( TQListViewItem *  )),this,TQT_SLOT(setMiniEditors ( TQListViewItem *  )));
  connect(lvInteractive,TQT_SIGNAL( selectionChanged( TQListViewItem *  )),this,TQT_SLOT(setMiniEditors ( TQListViewItem *  )));
  connect(lvPaged,TQT_SIGNAL( selectionChanged( TQListViewItem *  )),this,TQT_SLOT(setMiniEditors ( TQListViewItem *  )));
}

void CSSEditor::removeProperty(const TQVariant& v){
  m_properties.remove(v.toString());
  updatePreview();
}

TQString CSSEditor::generateProperties(){
  TQString props;
  TQMap<TQString,TQString>::Iterator it;
  if(!SHckb->isChecked()) {
    for ( it = m_properties.begin(); it != m_properties.end(); ++it )
      props+= it.key() + " : " + it.data().stripWhiteSpace() + "; " ;
    props.truncate(props.length()-1);//the last white space creates some problems: better remove it
    //props.chop(1);
    return props;
  }
  else {
    ShorthandFormer sf(m_properties);
    return sf.compress();
  }
}

void CSSEditor::updatePreview(){
  updateDisplay();
  activatePreview();
}

void CSSEditor::activatePreview() {
  if(!m_isFileToPreviewExternal){
   TQString testHeader,
                 testFooter,
                 testBody;

    if(!m_selectorName.isEmpty()) {
      testHeader +=  m_selectorName + " { \n ";
      testFooter =  "\n}"  + m_Selectors;
    }
    else {
      testHeader += " style=\"" ;
      testFooter = "\"" ;
    }

    TQMap<TQString,TQString>::Iterator it;
    for ( it = m_properties.begin(); it != m_properties.end(); ++it )
      testBody+= it.key() + " : " + it.data() + ";";

    m_previewer->begin( KURL(m_fileToPreview) );
    m_previewer->write( m_Header +  testHeader + testBody+ testFooter+ m_Footer);
    m_previewer->end();


  }
  else {
    TQString tmp("{");
    TQFile file(m_fileToPreview);
    if ( file.open( IO_ReadOnly ) ) {
        TQMap<TQString,TQString>::Iterator it;
        for ( it = m_properties.begin(); it != m_properties.end(); ++it )
          tmp+= it.key() + " : " + it.data() + ";";


        TQFileInfo fi(m_fileToPreview);
        KParts::URLArgs a;
        if(fi.extension().lower() == "xml" || fi.extension().lower() == "xhtml")
          a.serviceType="text/xml";
        if(fi.extension().lower() == "html" || fi.extension().lower() == "html")
          a.serviceType="text/xml";
        m_previewer->browserExtension()->setURLArgs(a);
        TQTextStream stream( &file );

        m_previewer->begin(KURL(m_fileToPreview));
        m_previewer->write(stream.read());
        m_previewer->end();
        m_previewer->setUserStyleSheet(m_externalStyleSheetDefinition + " " + m_selectorName+" "+ tmp +"}");
        file.close();
    }
   //else KMessageBox::sorry(this,i18n("The css file you want to edit can't be opened"));
  }
}

void CSSEditor::updateDisplay(){
  TQString toDisplay;
  TQMap<TQString,TQString>::Iterator it;
  for ( it = m_properties.begin(); it != m_properties.end(); ++it )
    toDisplay += it.key() + " : " + it.data() + ";\n\t";

  if(!m_selectorName.isEmpty()){// we're working on <style></style> block
    toDisplay.prepend(m_selectorName +" {\n\t");
    toDisplay+="}";
  }
  else  toDisplay.prepend("\n\t");

  display->setText(toDisplay);
}

#include "csseditor.moc"