]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QCharacter.C
some more random changes, added Timeout (make clean if LyX crashes !!)
[lyx.git] / src / frontends / qt2 / QCharacter.C
1 /**
2  * \file QCharacter.C
3  * Copyright 2001 The LyX Team.
4  * See the file COPYING.
5  *
6  * \author Edwin Leuven, leuven@fee.uva.nl
7  */
8
9 #include <config.h>
10
11 #include "gettext.h"
12 #include "QCharacterDialog.h"
13 #include "QCharacter.h"
14 #include "bufferview_funcs.h"
15 #include "Dialogs.h"
16 #include "Liason.h"
17 #include "QtLyXView.h"
18 #include "buffer.h"
19 #include "lyxtext.h"
20 #include "language.h"
21 #include "support/lstrings.h"
22 #include "BufferView.h"
23
24 using SigC::slot;
25 using Liason::setMinibuffer;
26
27 QCharacter::QCharacter(LyXView *v, Dialogs *d)
28         : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
29 {
30         d->showCharacter.connect(slot(this, &QCharacter::show));
31         // for LFUN_FREE
32         d->setUserFreeFont.connect(slot(this, &QCharacter::apply));
33 }
34
35
36 QCharacter::~QCharacter()
37 {
38         delete dialog_;
39 }
40
41
42 void QCharacter::apply()
43 {
44         if (!lv_->view()->available() || !dialog_)
45                 return;
46
47         LyXFont font = dialog_->getChar();
48
49         if (dialog_->langItem()==1)
50                 font.setLanguage(lv_->buffer()->params.language);
51
52         toggleAndShow(lv_->view(), font, dialog_->toggleAll());
53         lv_->view()->setState();
54         lv_->buffer()->markDirty();
55         setMinibuffer(lv_, _("Character set"));
56 }
57  
58
59 void QCharacter::show()
60 {
61         if (!dialog_) {
62                 dialog_ = new QCharacterDialog(this, 0, _("Character Settings"), false);
63  
64                 // add languages
65                 for (Languages::const_iterator cit = languages.begin();
66                         cit != languages.end(); ++cit) {
67                         string const language = cit->second.lang();
68                         dialog_->lang->insertItem(tostr(language).c_str(), -1);
69                 }
70         }
71
72         if (!dialog_->isVisible()) {
73                 h_ = d_->hideBufferDependent.connect(slot(this, &QCharacter::hide));
74                 u_ = d_->updateBufferDependent.connect(slot(this, &QCharacter::update));
75         }
76
77         dialog_->raise();
78         dialog_->setActiveWindow();
79         update();
80         dialog_->show();
81 }
82
83  
84 void QCharacter::close()
85 {
86         h_.disconnect();
87         u_.disconnect();
88 }
89
90
91 void QCharacter::hide()
92 {
93         dialog_->hide();
94         close();
95 }
96
97
98 void QCharacter::update(bool)
99 {
100         if (!lv_->view()->available())
101                 return;
102
103         dialog_->setReadOnly(lv_->buffer()->isReadonly());
104 }