]> git.lyx.org Git - features.git/blob - src/frontends/qt2/FormCharacter.C
outstanding changes
[features.git] / src / frontends / qt2 / FormCharacter.C
1 /**
2  * \file FormCharacter.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 "chardlgimpl.h"
13 #include "FormCharacter.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 FormCharacter::FormCharacter(LyXView *v, Dialogs *d)
28         : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
29 {
30         // let the dialog be shown
31         // This is a permanent connection so we won't bother
32         // storing a copy because we won't be disconnecting.
33         d->showCharacter.connect(slot(this, &FormCharacter::show));
34         // for LFUN_FREE
35         d->setUserFreeFont.connect(slot(this, &FormCharacter::apply));
36 }
37
38
39 FormCharacter::~FormCharacter()
40 {
41         delete dialog_;
42 }
43
44
45 void FormCharacter::apply()
46 {
47         if (!lv_->view()->available() || !dialog_)
48                 return;
49
50         LyXFont font = dialog_->getChar();
51
52         if (dialog_->langItem()==1)
53                 font.setLanguage(lv_->buffer()->params.language);
54
55         ToggleAndShow(lv_->view(), font, dialog_->toggleAll());
56         lv_->view()->setState();
57         lv_->buffer()->markDirty();
58         setMinibuffer(lv_, _("Character set"));
59 }
60
61 void FormCharacter::show()
62 {
63         if (!dialog_) {
64                 dialog_ = new CharDlgImpl(this, 0, _("Character Options"), false);
65                 // add languages
66                 for (Languages::const_iterator cit = languages.begin();
67                         cit != languages.end(); ++cit) {
68                         const string language = (*cit).second.lang();
69                         dialog_->lang->insertItem( tostr(language).c_str(), -1 );
70                 }
71         }
72
73         if (!dialog_->isVisible()) {
74                 h_ = d_->hideBufferDependent.connect(slot(this, &FormCharacter::hide));
75                 u_ = d_->updateBufferDependent.connect(slot(this, &FormCharacter::update));
76         }
77
78         dialog_->raise();
79         dialog_->setActiveWindow();
80         update();
81         dialog_->show();
82 }
83
84 void FormCharacter::close()
85 {
86         h_.disconnect();
87         u_.disconnect();
88 }
89
90 void FormCharacter::hide()
91 {
92         dialog_->hide();
93         close();
94 }
95
96 void FormCharacter::update(bool)
97 {
98         if (!lv_->view()->available())
99                 return;
100
101         dialog_->setReadOnly(lv_->buffer()->isReadonly());
102 }