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