GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — sqlitebrowser/src/EditDialog.cpp at master · Processoriented/sqlitebrowser Expand file tree/ Copy pathEditDialog.cppMore file actions 202 lines (170 loc) · 5.7 KB / Copy pathEditDialog.cppFile metadata and controls202 lines (170 loc) · 5.7 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 #include "EditDialog.h" #include "ui_EditDialog.h" #include "sqlitedb.h" #include "PreferencesDialog.h" #include "src/qhexedit.h" #include "FileDialog.h" #include <QKeySequence> #include <QShortcut> EditDialog::EditDialog(QWidget* parent) : QDialog(parent), ui(new Ui::EditDialog) { ui->setupUi(this); ui->buttonBox->button(QDialogButtonBox::Ok)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Return)); QHBoxLayout* hexLayout = new QHBoxLayout(ui->editorBinary); hexEdit = new QHexEdit(this); hexLayout->addWidget(hexEdit); hexEdit->setOverwriteMode(false); connect(hexEdit, SIGNAL(dataChanged()), this, SLOT(hexDataChanged())); QShortcut* ins = new QShortcut(QKeySequence(Qt::Key_Insert), this); connect(ins, SIGNAL(activated()), this, SLOT(toggleOverwriteMode())); reset(); } EditDialog::~EditDialog() { delete ui; } void EditDialog::reset() { curRow = -1; curCol = -1; ui->editorText->clear(); ui->editorText->setFocus(); ui->editorImage->clear(); hexEdit->setData(QByteArray()); oldData = ""; checkDataType(); } void EditDialog::closeEvent(QCloseEvent*) { emit goingAway(); } void EditDialog::loadText(const QByteArray& data, int row, int col) { curRow = row; curCol = col; oldData = data; QString textData = QString::fromUtf8(data.constData(), data.size()); ui->editorText->setPlainText(textData); ui->editorText->setFocus(); ui->editorText->selectAll(); hexEdit->setData(data); // Assume it's binary data and only call checkDatyType afterwards. This means the correct input widget is selected here in all cases // but once the user changed it to text input it will stay there. ui->editorStack->setCurrentIndex(1); checkDataType(); } void EditDialog::importData() { // Get list of supported image file formats to include them in the file dialog filter QString image_formats; QList<QByteArray> image_formats_list = QImageReader::supportedImageFormats(); for(int i=0;i<image_formats_list.size();++i) image_formats.append(QString("*.%1 ").arg(QString::fromUtf8(image_formats_list.at(i)))); QString fileName = FileDialog::getOpenFileName( this, tr("Choose a file") #ifndef Q_OS_MAC // Filters on OS X are buggy , tr("Text files(*.txt);;Image files(%1);;All files(*)").arg(image_formats) #endif ); if(QFile::exists(fileName)) { QFile file(fileName); if(file.open(QIODevice::ReadOnly)) { QByteArray d = file.readAll(); hexEdit->setData(d); ui->editorText->setPlainText(d); checkDataType(); file.close(); } } } void EditDialog::exportData() { QString fileName = FileDialog::getSaveFileName( this, tr("Choose a filename to export data"), tr("Text files(*.txt);;All files(*)")); if(fileName.size() > 0) { QFile file(fileName); if(file.open(QIODevice::WriteOnly)) { file.write(hexEdit->data()); file.close(); } } } void EditDialog::clearData() { ui->editorText->clear(); ui->editorImage->clear(); hexEdit->setData(QByteArray()); checkDataType(); ui->editorText->setFocus(); } void EditDialog::accept() { // Don't update if the data hasn't changed // To differentiate NULL and empty byte arrays, we also compare the NULL flag if(hexEdit->data() != oldData || hexEdit->data().isNull() != oldData.isNull()) emit updateRecordText(curRow, curCol, hexEdit->data()); emit goingAway(); } void EditDialog::editTextChanged() { if(ui->editorText->hasFocus()) { hexEdit->setData(ui->editorText->toPlainText().toUtf8()); checkDataType(); } } void EditDialog::hexDataChanged() { // Update the text editor accordingly ui->editorText->setPlainText(QString::fromUtf8(hexEdit->data().constData(), hexEdit->data().size())); } void EditDialog::checkDataType() { ui->comboEditor->setVisible(true); // Assume NULL type first if (hexEdit->data().isNull()) ui->labelType->setText(tr("Type of data currently in cell: Null")); // Check if data is text only if(QString(hexEdit->data()).toUtf8() == hexEdit->data()) // Any proper way?? { ui->editorStack->setCurrentIndex(0); ui->labelBinayWarning->setVisible(false); if (!hexEdit->data().isNull()) ui->labelType->setText(tr("Type of data currently in cell: Text / Numeric")); ui->labelSize->setText(tr("%n char(s)", "", hexEdit->data().length())); } else { // It's not. So it might be an image. QImage img; if(img.loadFromData(hexEdit->data())) { // It is. ui->editorImage->setPixmap(QPixmap::fromImage(img)); ui->editorStack->setCurrentIndex(2); ui->labelType->setText(tr("Type of data currently in cell: Image")); ui->labelSize->setText(tr("%1x%2 pixel").arg(ui->editorImage->pixmap()->size().width()).arg(ui->editorImage->pixmap()->size().height())); ui->comboEditor->setVisible(false); } else { // It's not. So it's probably some random binary data. ui->labelBinayWarning->setVisible(true); if (!hexEdit->data().isNull()) ui->labelType->setText(tr("Type of data currently in cell: Binary")); ui->labelSize->setText(tr("%n byte(s)", "", hexEdit->data().length())); } } } void EditDialog::toggleOverwriteMode() { static bool currentMode = false; currentMode = !currentMode; hexEdit->setOverwriteMode(currentMode); ui->editorText->setOverwriteMode(currentMode); } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |