summaryrefslogtreecommitdiffstats
path: root/quanta/dialogs/specialchardialog.cpp
blob: 3ea2911725c6b6b5463960ecd342afe31baf10c2 (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
/***************************************************************************
                     specialchardialog.cpp
                             -------------------

    copyright            : (C) 2004 - Michal Rudolf
    email                : mrudolf@tdewebdev.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 <tqfile.h>
#include <tqpushbutton.h>
#include <tqtextstream.h>
#include <tqregexp.h> 

#include <tdelocale.h>
#include <kstandarddirs.h>
#include <tdelistbox.h>
#include <klineedit.h>

#include "specialchardialog.h"
#include "resource.h"

SpecialCharDialog::SpecialCharDialog( TQWidget* parent, const char* name, bool modal, WFlags fl)
    :SpecialCharDialogS( parent, name, modal, fl )
{
  connect ( FilterLineEdit, TQT_SIGNAL(textChanged(const TQString&)), 
      TQT_SLOT(filterChars(const TQString&)) );
  connect ( CharsListBox, TQT_SIGNAL(doubleClicked(TQListBoxItem*)), 
      TQT_SLOT(insertCode()) );
  connect (buttonOk, TQT_SIGNAL(clicked()), TQT_SLOT(insertCode()));
  connect (buttonChar, TQT_SIGNAL(clicked()), TQT_SLOT(insertChar()));
  connect (buttonCancel, TQT_SIGNAL(clicked()), TQT_SLOT(cancel()));
  filterChars("");
}

SpecialCharDialog::~SpecialCharDialog()
{
}

void SpecialCharDialog::filterChars(const TQString& filter)
{
  CharsListBox->clear();
  if (filter.isEmpty())
    CharsListBox->insertStringList(charList);
  else {
    for (TQStringList::ConstIterator it = charList.begin(); it != charList.end(); ++it)
      if ( (*it).contains(filter, false) )
        CharsListBox->insertItem(*it);
  }
  if (CharsListBox->currentItem() == -1 && CharsListBox->count())
    CharsListBox->setCurrentItem(0);
}

TQString SpecialCharDialog::selection()
{
  return m_selection;
}

void SpecialCharDialog::insertCode()
{
  TQString selected = CharsListBox->text(CharsListBox->currentItem());
  int begin = selected.find("(&")+1;
  int length = selected.find(";)") - begin + 1;
  m_selection = selected.mid(begin, length);
  done(TQDialog::Accepted);
}

void SpecialCharDialog::insertChar()
{
  m_selection = CharsListBox->text(CharsListBox->currentItem()).left(1);
  done(TQDialog::Accepted);
}

void SpecialCharDialog::cancel()
{
  m_selection = "";
  done(TQDialog::Rejected);
}

#include "specialchardialog.moc"