summaryrefslogtreecommitdiffstats
path: root/quanta/components/csseditor/styleeditor.cpp
blob: e39e55640d8e1be58bc74bf56a9ba3c491f4059f (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
/***************************************************************************
                           styleeditor  -  implementation
    begin              : Wed Apr 7 2004
    copyright          : (C) 2004 by Luciano Gulmini <gulmini.luciano@student.unife.it>
 ***************************************************************************/

/***************************************************************************
 *
 *   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; version 2 of the License.
 *
 ***************************************************************************/

//qt includes
#include <tqlineedit.h>
#include <tqtooltip.h>
#include <tqiconset.h>
#include <tqlabel.h>
#include <tqfileinfo.h>

//kde includes
#include <kdialog.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kpushbutton.h>
#include <kurl.h>
#include <tdetexteditor/editinterface.h>
#include <tdetexteditor/viewcursorinterface.h>

//app includes
#include "parser.h"
#include "tag.h"
#include "node.h"
#include "project.h"
#include "resource.h"
#include "document.h"
#include "styleeditor.h"
#include "viewmanager.h"
#include "csseditor.h"

StyleEditor::StyleEditor(TQWidget *parent, const char* name) : TLPEditor(parent,name){
  connect(m_pb, TQT_SIGNAL(clicked()), this, TQT_SLOT(openCSSEditor()));
  setToolTip(i18n("Open css dialog"));
  TQIconSet iconSet =  SmallIconSet(TQString::fromLatin1("stylesheet"));
  TQPixmap pixMap = iconSet.pixmap( TQIconSet::Small, TQIconSet::Normal );
  m_pb->setIconSet(iconSet);
  m_iconWidth = pixMap.width();
  m_iconHeight = pixMap.height(); 
  m_pb->setFixedSize( m_iconWidth+8, m_iconHeight+8 );
  m_label->hide();
}

void StyleEditor::setButtonIcon(int width, int height){
  m_pb->setFixedSize( m_iconWidth+width, m_iconHeight+height );
}

void StyleEditor::openCSSEditor(){
  Document *w = ViewManager::ref()->activeDocument();
  if (!w) return;
  uint line, col;
  int bLine, bCol, eLine, eCol;
  bLine = bCol = eLine = eCol = 0;
  w->viewCursorIf->cursorPositionReal(&line, &col);
  if (line == 0 && col == 0)
    col++;
  //parser->rebuild(w);
  Node *node = parser->nodeAt(line, col, false);
  unsigned int lastLine = w->editIf->numLines() - 1;
  unsigned int lastCol = w->editIf->lineLength(lastLine);
  Node *styleNode = node;

  if (styleNode->tag->type == Tag::XmlTagEnd && styleNode->prev)
    styleNode = styleNode->prev;

  TQString fullDocument = w->editIf->text().stripWhiteSpace();

  if (styleNode && (styleNode->tag->type == Tag::XmlTag || styleNode->tag->type == Tag::Empty) ) {
    CSSEditor *dlg = new CSSEditor(this);
    TQFileInfo fi(ViewManager::ref()->currentURL());
    dlg->setFileToPreview(Project::ref()->projectBaseURL().path() +  fi.baseName(),false);

    styleNode->tag->beginPos(bLine, bCol);
    styleNode->tag->endPos(eLine, eCol);
    dlg->setFooter(">" + w->text(eLine, eCol + 1, lastLine, lastCol));

    TQString temp;
    if (styleNode->tag->hasAttribute("style")) {
      dlg->setInlineStyleContent(styleNode->tag->attributeValue("style"));
      Tag tempTag(*(styleNode->tag));
      tempTag.deleteAttribute("style");
      temp = tempTag.toString();
    }
    else {
      dlg->setInlineStyleContent(TQString());
      temp = styleNode->tag->toString();
    }

    temp = temp.left(temp.length()-1);//remove >
    temp = temp.right(temp.length()-1);//remove <
    dlg->setHeader(w->text(0, 0, bLine, bCol) + temp);

    dlg->initialize();
    if( dlg->exec() ) m_le->setText(dlg->generateProperties());
    delete dlg;
  }
}

#include "styleeditor.moc"