]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QRefDialog.C
enable Font cache only for MacOSX and inline width() for other platform.
[lyx.git] / src / frontends / qt4 / QRefDialog.C
1 /**
2  * \file QRefDialog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Kalle Dalheimer
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "QRefDialog.h"
15 #include "QRef.h"
16
17 #include <QLineEdit>
18 #include <QListWidget>
19 #include <QPushButton>
20 #include <QCloseEvent>
21
22 namespace lyx {
23 namespace frontend {
24
25 QRefDialog::QRefDialog(QRef * form)
26         : form_(form)
27 {
28         setupUi(this);
29
30         connect(okPB, SIGNAL(clicked()),
31                 form_, SLOT(slotOK()));
32         connect(applyPB, SIGNAL(clicked()),
33                 form_, SLOT(slotApply()));
34         connect(closePB, SIGNAL(clicked()),
35                 form_, SLOT(slotClose()));
36
37         connect( typeCO, SIGNAL( activated(int) ), 
38                 this, SLOT( changed_adaptor() ) );
39         connect( referenceED, SIGNAL( textChanged(const QString&) ), 
40                 this, SLOT( changed_adaptor() ) );
41         connect( nameED, SIGNAL( textChanged(const QString&) ), 
42                 this, SLOT( changed_adaptor() ) );
43         connect( refsLW, SIGNAL(  itemClicked(QListWidgetItem *) ), 
44                 this, SLOT( refHighlighted(QListWidgetItem *) ) );
45         connect( refsLW, SIGNAL(  itemActivated(QListWidgetItem *) ), 
46                 this, SLOT( refSelected(QListWidgetItem *) ) );
47         connect( sortCB, SIGNAL( toggled(bool) ),
48                 this, SLOT( sortToggled(bool) ) );
49         connect( gotoPB, SIGNAL( clicked() ), 
50                 this, SLOT( gotoClicked() ) );
51         connect( updatePB, SIGNAL( clicked() ), 
52                 this, SLOT( updateClicked() ) );
53         connect( bufferCO, SIGNAL( activated(int) ), 
54                 this, SLOT( updateClicked() ) );
55
56 }
57
58 void QRefDialog::show()
59 {
60         QDialog::show();
61         refsLW->setFocus();
62 }
63
64
65 void QRefDialog::changed_adaptor()
66 {
67         form_->changed();
68 }
69
70
71 void QRefDialog::gotoClicked()
72 {
73         form_->gotoRef();
74 }
75
76
77 void QRefDialog::refHighlighted(QListWidgetItem * sel)
78 {
79         if (form_->readOnly())
80                 return;
81
82 /*      int const cur_item = refsLW->currentRow();
83         bool const cur_item_selected = cur_item >= 0 ?
84                 refsLB->isSelected(cur_item) : false;*/
85         bool const cur_item_selected = refsLW->isItemSelected(sel);
86
87         if (cur_item_selected)
88                 referenceED->setText(sel->text());
89
90         if (form_->at_ref_)
91                 form_->gotoRef();
92         gotoPB->setEnabled(true);
93         if (form_->typeAllowed())
94                 typeCO->setEnabled(true);
95         if (form_->nameAllowed())
96                 nameED->setEnabled(true);
97 }
98
99
100 void QRefDialog::refSelected(QListWidgetItem * sel)
101 {
102         if (form_->readOnly())
103                 return;
104
105 /*      int const cur_item = refsLW->currentRow();
106         bool const cur_item_selected = cur_item >= 0 ?
107                 refsLB->isSelected(cur_item) : false;*/
108         bool const cur_item_selected = refsLW->isItemSelected(sel);
109
110         if (cur_item_selected)
111                 referenceED->setText(sel->text());
112         // <enter> or double click, inserts ref and closes dialog
113         form_->slotOK();
114 }
115
116
117 void QRefDialog::sortToggled(bool on)
118 {
119         form_->sort_ = on;
120         form_->redoRefs();
121 }
122
123
124 void QRefDialog::updateClicked()
125 {
126         form_->updateRefs();
127 }
128
129
130 void QRefDialog::closeEvent(QCloseEvent * e)
131 {
132         form_->slotWMHide();
133         e->accept();
134 }
135
136 } // namespace frontend
137 } // namespace lyx
138
139 #include "QRefDialog_moc.cpp"