00001 #include <QtGui>
00002 #include <QLayout>
00003 #include <QMessageBox>
00004 #include <QColor>
00005 #include <QStyle>
00006 #include <QPalette>
00007
00008 #include "editor.h"
00009 #include "main.h"
00010
00011 editor::editor(int mode, QWidget *parent) : QWidget(parent)
00012 {
00013 setup_buttons();
00014 setup_editor_area();
00015
00016 setup_signals();
00017
00018 assembly_buttons();
00019
00020 if(mode==ENABLE_ASSEMBLY)
00021 assembly();
00022 }
00023
00024
00025 editor::~editor(void)
00026 {
00027
00028 }
00029
00030
00031
00032 void editor::setup_signals(void)
00033 {
00034 connect(bold,SIGNAL(clicked()), this,SLOT(on_bold_clicked()));
00035 connect(italic,SIGNAL(clicked()), this,SLOT(on_italic_clicked()));
00036 connect(underline,SIGNAL(clicked()), this,SLOT(on_underline_clicked()));
00037 connect(numericlist,SIGNAL(clicked()),this,SLOT(on_numericlist_clicked()));
00038 connect(dotlist,SIGNAL(clicked()), this,SLOT(on_dotlist_clicked()));
00039 connect(indentplus,SIGNAL(clicked()), this,SLOT(on_indentplus_clicked()));
00040 connect(indentminus,SIGNAL(clicked()),this,SLOT(on_indentminus_clicked()));
00041 connect(showhtml,SIGNAL(clicked()), this,SLOT(on_showhtml_clicked()));
00042 }
00043
00044
00045
00046 void editor::setup_buttons(void)
00047 {
00048
00049 bold = new QToolButton(this);
00050 bold->setText(tr("B"));
00051 bold->setObjectName("bold");
00052 QFont font;
00053 font.setBold(true);
00054 font.setWeight(75);
00055 bold->setFont(font);
00056
00057
00058 italic = new QToolButton(this);
00059 italic->setText(tr("I"));
00060 italic->setObjectName("italic");
00061 QFont font1;
00062 font1.setItalic(true);
00063 italic->setFont(font1);
00064
00065
00066 underline = new QToolButton(this);
00067 underline->setText(tr("U"));
00068 underline->setObjectName("underline");
00069 QFont font2;
00070 font2.setUnderline(true);
00071 underline->setFont(font2);
00072
00073
00074 numericlist = new QToolButton(this);
00075 numericlist->setText(tr("123"));
00076 numericlist->setObjectName("numericlist");
00077 QFont font3;
00078 font3.setPointSize(7);
00079 numericlist->setFont(font3);
00080
00081
00082 dotlist = new QToolButton(this);
00083 dotlist->setText(tr(":"));
00084 dotlist->setObjectName("dotlist");
00085 QFont font4;
00086 font4.setPointSize(7);
00087 font4.setBold(true);
00088 font4.setWeight(75);
00089 dotlist->setFont(font4);
00090
00091
00092 indentplus = new QToolButton(this);
00093 indentplus->setText(tr(">>"));
00094 indentplus->setObjectName("indentplus");
00095 indentplus->setFont(font3);
00096
00097
00098 indentminus = new QToolButton(this);
00099 indentminus->setText(tr("<<"));
00100 indentminus->setObjectName("indentminus");
00101 indentminus->setFont(font3);
00102
00103
00104 fontselect = new QFontComboBox(this);
00105 fontselect->setObjectName("fontselect");
00106
00107
00108 fontsize = new QSpinBox(this);
00109 fontsize->setObjectName("fontsize");
00110 fontsize->setMinimum(5);
00111 fontsize->setMaximum(100);
00112 fontsize->setValue(10);
00113
00114
00115 showhtml = new QToolButton(this);
00116 showhtml->setText(tr("HTML"));
00117 showhtml->setObjectName("showhtml");
00118 QFont font5;
00119 font5.setPointSize(5);
00120 showhtml->setFont(font5);
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 }
00131
00132
00133
00134 void editor::setup_editor_area(void)
00135 {
00136
00137 textarea=new QTextEdit(this);
00138 textarea->setObjectName("textarea");
00139 }
00140
00141
00142
00143 void editor::assembly_buttons(void)
00144 {
00145
00146 textformat_buttons_layout=new QHBoxLayout();
00147 textformat_buttons_layout->setObjectName("textformat_buttons_layout");
00148
00149 textformat_buttons_layout->addWidget(bold);
00150 textformat_buttons_layout->addWidget(italic);
00151 textformat_buttons_layout->addWidget(underline);
00152 textformat_buttons_layout->addWidget(numericlist);
00153 textformat_buttons_layout->addWidget(dotlist);
00154 textformat_buttons_layout->addWidget(indentplus);
00155 textformat_buttons_layout->addWidget(indentminus);
00156 textformat_buttons_layout->addWidget(fontselect);
00157 textformat_buttons_layout->addWidget(fontsize);
00158 textformat_buttons_layout->addWidget(showhtml);
00159 }
00160
00161
00162
00163 void editor::assembly(void)
00164 {
00165
00166
00167 buttons_and_edit_layout=new QVBoxLayout(this);
00168 buttons_and_edit_layout->setObjectName(QString::fromUtf8("buttons_and_edit_layout"));
00169
00170
00171 buttons_and_edit_layout->addLayout(textformat_buttons_layout);
00172
00173
00174 buttons_and_edit_layout->addWidget(textarea);
00175
00176
00177 setLayout(buttons_and_edit_layout);
00178
00179
00180 QLayout *lt;
00181 lt=layout();
00182 lt->setContentsMargins(0,2,0,0);
00183 }
00184
00185
00186
00187 void editor::set_textarea(QString text)
00188 {
00189 textarea->setHtml(text);
00190 }
00191
00192
00193
00194 void editor::set_textarea_editable(bool editable)
00195 {
00196
00197
00198
00199 if(editable==true)
00200 {
00201 textarea->setTextInteractionFlags(Qt::TextEditorInteraction);
00202 textarea->setPalette(qApp->palette());
00203
00204 }
00205 else
00206 {
00207 textarea->setTextInteractionFlags(Qt::TextBrowserInteraction);
00208
00209 QPalette plt=qApp->palette();
00210 QColor inactive_color;
00211
00212 inactive_color=qApp->palette().color(QPalette::Disabled, QPalette::Window);
00213 plt.setColor(QPalette::Normal, QPalette::Base, inactive_color);
00214 textarea->setPalette(plt);
00215
00216
00217 }
00218 }
00219
00220
00221
00222 QString editor::get_textarea(void)
00223 {
00224 return textarea->toHtml();
00225 }
00226
00228
00230
00231
00232 void editor::on_bold_clicked(void)
00233 {
00234 if(!(textarea->fontWeight()==75))
00235 textarea->setFontWeight(75);
00236 else
00237 textarea->setFontWeight(0);
00238 }
00239
00240
00241 void editor::on_italic_clicked(void)
00242 {
00243 if(!textarea->fontItalic())
00244 textarea->setFontItalic(true);
00245 else
00246 textarea->setFontItalic(false);
00247 }
00248
00249
00250 void editor::on_underline_clicked(void)
00251 {
00252 if(!textarea->fontUnderline())
00253 textarea->setFontUnderline(true);
00254 else
00255 textarea->setFontUnderline(false);
00256 }
00257
00258 void editor::format_to_list(QTextListFormat::Style setformat)
00259 {
00260
00261 QTextListFormat format;
00262 format.setStyle(setformat);
00263
00264
00265 if(textarea->textCursor().hasSelection())
00266 {
00267
00268 textarea->textCursor().createList(format);
00269 }
00270 else
00271 {
00272
00273 textarea->textCursor().insertList(format);
00274 }
00275
00276
00277 textarea->ensureCursorVisible();
00278 }
00279
00280
00281
00282 void editor::on_numericlist_clicked(void)
00283 {
00284 format_to_list(QTextListFormat::ListDecimal);
00285 }
00286
00287
00288
00289 void editor::on_dotlist_clicked(void)
00290 {
00291 format_to_list(QTextListFormat::ListDisc);
00292 }
00293
00294
00295
00296 void editor::on_indentplus_clicked(void)
00297 {
00298 int currentindent;
00299
00300
00301 currentindent=(int) textarea->textCursor().blockFormat().leftMargin();
00302
00303
00304 QTextBlockFormat indentformatting;
00305 indentformatting.setLeftMargin(currentindent+10);
00306
00307
00308 textarea->textCursor().setBlockFormat(indentformatting);
00309 }
00310
00311
00312
00313 void editor::on_indentminus_clicked(void)
00314 {
00315 int currentindent,indentforset;
00316
00317
00318 currentindent=(int) textarea->textCursor().blockFormat().leftMargin();
00319
00320 if((currentindent-10)>0)indentforset=currentindent-10;
00321 else indentforset=0;
00322
00323
00324 QTextBlockFormat indentformatting;
00325 indentformatting.setLeftMargin(indentforset);
00326
00327
00328 textarea->textCursor().setBlockFormat(indentformatting);
00329 }
00330
00331
00332
00333 void editor::on_showhtml_clicked(void)
00334 {
00335 info_window(textarea->toHtml());
00336 }
00337