| 1 | /****************************************************************************
|
|---|
| 2 | ** $Id: imagetexteditor.cpp 2 2005-11-16 15:49:26Z dmik $
|
|---|
| 3 | **
|
|---|
| 4 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of an example program for Qt. This example
|
|---|
| 7 | ** program may be used, distributed and modified without limitation.
|
|---|
| 8 | **
|
|---|
| 9 | *****************************************************************************/
|
|---|
| 10 |
|
|---|
| 11 | #include "imagetexteditor.h"
|
|---|
| 12 | #include <qimage.h>
|
|---|
| 13 | #include <qlayout.h>
|
|---|
| 14 | #include <qgrid.h>
|
|---|
| 15 | #include <qvbox.h>
|
|---|
| 16 | #include <qhbox.h>
|
|---|
| 17 | #include <qcombobox.h>
|
|---|
| 18 | #include <qmultilineedit.h>
|
|---|
| 19 | #include <qlabel.h>
|
|---|
| 20 | #include <qlineedit.h>
|
|---|
| 21 | #include <qlistbox.h>
|
|---|
| 22 | #include <qpushbutton.h>
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | ImageTextEditor::ImageTextEditor( QImage& i, QWidget *parent, const char *name, WFlags f ) :
|
|---|
| 26 | QDialog(parent,name,TRUE,f),
|
|---|
| 27 | image(i)
|
|---|
| 28 | {
|
|---|
| 29 | QVBoxLayout* vbox = new QVBoxLayout(this,8);
|
|---|
| 30 | vbox->setAutoAdd(TRUE);
|
|---|
| 31 |
|
|---|
| 32 | QGrid* controls = new QGrid(3,QGrid::Horizontal,this);
|
|---|
| 33 | controls->setSpacing(8);
|
|---|
| 34 | QLabel* l;
|
|---|
| 35 | l=new QLabel("Language",controls); l->setAlignment(AlignCenter);
|
|---|
| 36 | l=new QLabel("Key",controls); l->setAlignment(AlignCenter);
|
|---|
| 37 | (void)new QLabel("",controls); // dummy
|
|---|
| 38 | languages = new QComboBox(controls);
|
|---|
| 39 | keys = new QComboBox(controls);
|
|---|
| 40 | QPushButton* remove = new QPushButton("Remove",controls);
|
|---|
| 41 |
|
|---|
| 42 | newlang = new QLineEdit(controls);
|
|---|
| 43 | newkey = new QLineEdit(controls);
|
|---|
| 44 | QPushButton* add = new QPushButton("Add",controls);
|
|---|
| 45 |
|
|---|
| 46 | text = new QMultiLineEdit(this);
|
|---|
| 47 |
|
|---|
| 48 | QHBox* hbox = new QHBox(this);
|
|---|
| 49 | QPushButton* cancel = new QPushButton("Cancel",hbox);
|
|---|
| 50 | QPushButton* ok = new QPushButton("OK",hbox);
|
|---|
| 51 |
|
|---|
| 52 | connect(add,SIGNAL(clicked()),
|
|---|
| 53 | this,SLOT(addText()));
|
|---|
| 54 |
|
|---|
| 55 | connect(remove,SIGNAL(clicked()),
|
|---|
| 56 | this,SLOT(removeText()));
|
|---|
| 57 |
|
|---|
| 58 | connect(ok,SIGNAL(clicked()),
|
|---|
| 59 | this,SLOT(accept()));
|
|---|
| 60 |
|
|---|
| 61 | connect(cancel,SIGNAL(clicked()),
|
|---|
| 62 | this,SLOT(reject()));
|
|---|
| 63 |
|
|---|
| 64 | connect(languages,SIGNAL(activated(int)),
|
|---|
| 65 | this,SLOT(updateText()));
|
|---|
| 66 |
|
|---|
| 67 | connect(keys,SIGNAL(activated(int)),
|
|---|
| 68 | this,SLOT(updateText()));
|
|---|
| 69 |
|
|---|
| 70 | imageChanged();
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | ImageTextEditor::~ImageTextEditor()
|
|---|
| 74 | {
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | void ImageTextEditor::imageChanged()
|
|---|
| 78 | {
|
|---|
| 79 | languages->clear();
|
|---|
| 80 | keys->clear();
|
|---|
| 81 | text->clear();
|
|---|
| 82 | languages->insertItem("<any>");
|
|---|
| 83 |
|
|---|
| 84 | languages->insertStringList(image.textLanguages());
|
|---|
| 85 | keys->insertStringList(image.textKeys());
|
|---|
| 86 |
|
|---|
| 87 | updateText();
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | void ImageTextEditor::accept()
|
|---|
| 91 | {
|
|---|
| 92 | storeText();
|
|---|
| 93 | QDialog::accept();
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | void ImageTextEditor::updateText()
|
|---|
| 97 | {
|
|---|
| 98 | storeText();
|
|---|
| 99 | newlang->setText(languages->currentText());
|
|---|
| 100 | newkey->setText(keys->currentText());
|
|---|
| 101 | QString t = image.text(currKey(),currLang());
|
|---|
| 102 |
|
|---|
| 103 | text->setText(t);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | QString ImageTextEditor::currKey()
|
|---|
| 107 | {
|
|---|
| 108 | return newkey->text();
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | QString ImageTextEditor::currLang()
|
|---|
| 112 | {
|
|---|
| 113 | QString l = newlang->text();
|
|---|
| 114 | if ( l=="<any>" )
|
|---|
| 115 | l = QString::null;
|
|---|
| 116 | return l;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | QString ImageTextEditor::currText()
|
|---|
| 120 | {
|
|---|
| 121 | QString t = text->text();
|
|---|
| 122 | if ( t.isNull() ) t = "";
|
|---|
| 123 | return t;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 | void ImageTextEditor::removeText()
|
|---|
| 128 | {
|
|---|
| 129 | image.setText(currKey(),currLang(),QString::null);
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | void ImageTextEditor::addText()
|
|---|
| 133 | {
|
|---|
| 134 | storeText();
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | void ImageTextEditor::storeText()
|
|---|
| 138 | {
|
|---|
| 139 | if ( currKey().length() > 0 ) {
|
|---|
| 140 | image.setText(currKey(),currLang(),currText());
|
|---|
| 141 | }
|
|---|
| 142 | }
|
|---|