]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FormCharacter.C
remove CXX_WORKING_NAMESPACES
[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 Liason::setMinibuffer;
23
24 FormCharacter::FormCharacter(LyXView *v, Dialogs *d)
25         : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
26 {
27    // let the popup be shown
28    // This is a permanent connection so we won't bother
29    // storing a copy because we won't be disconnecting.
30    d->showLayoutCharacter.connect(slot(this, &FormCharacter::show));
31    // for LFUN_FREE
32    d->setUserFreeFont.connect(slot(this, &FormCharacter::apply));
33 }
34
35
36 FormCharacter::~FormCharacter()
37 {
38    delete dialog_;
39 }
40
41
42 void FormCharacter::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 void FormCharacter::show()
59 {
60    if (!dialog_) {
61       dialog_ = new CharDlgImpl(this, 0, _("Character Options"), false);
62       // add languages
63       for (Languages::const_iterator cit = languages.begin();
64            cit != languages.end(); ++cit) {
65          const string language = (*cit).second.lang();
66          dialog_->lang->insertItem( tostr(language).c_str(), -1 );
67       }
68    }
69
70    if (!dialog_->isVisible()) {
71       h_ = d_->hideBufferDependent.connect(slot(this, &FormCharacter::hide));
72       u_ = d_->updateBufferDependent.connect(slot(this, &FormCharacter::update));
73    }
74    
75    dialog_->raise();
76    dialog_->setActiveWindow();
77    update();
78    dialog_->show();
79 }
80
81 void FormCharacter::close()
82 {
83    h_.disconnect();
84    u_.disconnect();
85 }
86
87 void FormCharacter::hide()
88 {
89    dialog_->hide();
90    close();
91 }
92
93 void FormCharacter::update(bool)
94 {
95         
96    if (!lv_->view()->available())
97      return;
98    
99    dialog_->setReadOnly(lv_->buffer()->isReadonly());
100 }