void AlterTable::on_actionRenombrar_Tabla_triggered() { QDialog dialog(this); dialog.setWindowTitle("Renombrar Tabla"); QLabel messageLabel("Nuevo Nombre: ", &dialog); QLineEdit tableNameLineEdit(&dialog); QPushButton renamePushButton("Renombrar", &dialog); QPushButton cancelPushButton("Cancelar", &dialog); connect(&renamePushButton, SIGNAL(clicked()), &dialog, SLOT(accept())); connect(&cancelPushButton, SIGNAL(clicked()), &dialog, SLOT(reject())); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(&messageLabel); layout->addWidget(&tableNameLineEdit); QHBoxLayout *buttonsLayout = new QHBoxLayout; buttonsLayout->addWidget(&renamePushButton); buttonsLayout->addWidget(&cancelPushButton); layout->addLayout(buttonsLayout); dialog.setLayout(layout); if (dialog.exec() == QDialog::Rejected) { return; } QSqlQuery query(*db); query.exec("ALTER TABLE " + tableName + " RENAME TO " + tableNameLineEdit.text() + ";"); if (query.lastError().isValid()) { QMessageBox mBox(this); mBox.setWindowTitle("ERROR"); mBox.setIcon(QMessageBox::Critical); mBox.setText( "No se puede realizar la operación de renombrado de: " + tableName); mBox.exec(); return; } tableName = tableNameLineEdit.text(); setWindowTitle("Alterar Tabla: " + tableName); QString strQuery; if (engineName == "sqlite") { strQuery = QString("PRAGMA table_info(%1)").arg(tableName); } else if (engineName == "mysql") { strQuery = QString("SHOW COLUMNS FROM %1").arg(tableName); } queryModel->setQuery(strQuery); }
QVariant ChatLineModelItem::data(int column, int role) const { if (role == ChatLineModel::MsgLabelRole) return messageLabel(); QVariant variant; MessageModel::ColumnType col = (MessageModel::ColumnType)column; switch (col) { case ChatLineModel::TimestampColumn: variant = timestampData(role); break; case ChatLineModel::SenderColumn: variant = senderData(role); break; case ChatLineModel::ContentsColumn: variant = contentsData(role); break; default: break; } if (!variant.isValid()) return MessageModelItem::data(column, role); return variant; }
NotificationDialog::NotificationDialog(Notification *notification, QWidget *parent) : QDialog(parent), m_notification(notification), m_closeLabel(nullptr), m_closeTimer(0) { QFrame *notificationFrame(new QFrame(this)); notificationFrame->setObjectName(QLatin1String("notificationFrame")); notificationFrame->setStyleSheet(QLatin1String("#notificationFrame {padding:5px;border:1px solid #CCC;border-radius:10px;background:#F0F0f0;}")); notificationFrame->setCursor(QCursor(Qt::PointingHandCursor)); notificationFrame->installEventFilter(this); QBoxLayout *mainLayout(new QBoxLayout(QBoxLayout::LeftToRight)); mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->setSpacing(0); mainLayout->setSizeConstraint(QLayout::SetMinimumSize); mainLayout->addWidget(notificationFrame); QLabel *iconLabel(new QLabel(this)); iconLabel->setPixmap(ThemesManager::createIcon(QLatin1String("otter-browser-32")).pixmap(32, 32)); iconLabel->setStyleSheet(QLatin1String("padding:5px;")); QLabel *messageLabel(new QLabel(this)); messageLabel->setText(m_notification->getMessage()); messageLabel->setStyleSheet(QLatin1String("padding:5px;font-size:13px;")); messageLabel->setWordWrap(true); QStyleOption option; option.rect = QRect(0, 0, 16, 16); QPixmap pixmap(16, 16); pixmap.fill(Qt::transparent); QPainter painter(&pixmap); style()->drawPrimitive(QStyle::PE_IndicatorTabClose, &option, &painter, this); m_closeLabel = new QLabel(notificationFrame); m_closeLabel->setToolTip(tr("Close")); m_closeLabel->setPixmap(pixmap); m_closeLabel->setAlignment(Qt::AlignTop); m_closeLabel->setMargin(5); m_closeLabel->installEventFilter(this); QBoxLayout *notificationLayout(new QBoxLayout(QBoxLayout::LeftToRight)); notificationLayout->setContentsMargins(0, 0, 0, 0); notificationLayout->setSpacing(0); notificationLayout->setSizeConstraint(QLayout::SetMinimumSize); notificationLayout->addWidget(iconLabel); notificationLayout->addWidget(messageLabel); notificationLayout->addWidget(m_closeLabel); notificationFrame->setLayout(notificationLayout); setLayout(mainLayout); setFixedWidth(400); setMinimumHeight(50); setMaximumHeight(150); setWindowOpacity(0); setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Tool | Qt::FramelessWindowHint); setFocusPolicy(Qt::NoFocus); setAttribute(Qt::WA_DeleteOnClose, true); setAttribute(Qt::WA_ShowWithoutActivating, true); setAttribute(Qt::WA_TranslucentBackground, true); adjustSize(); m_animation = new QPropertyAnimation(this, QStringLiteral("windowOpacity").toLatin1()); m_animation->setDuration(500); m_animation->setStartValue(0.0); m_animation->setEndValue(1.0); m_animation->start(); const int visibilityDuration(SettingsManager::getOption(SettingsManager::Interface_NotificationVisibilityDurationOption).toInt()); if (visibilityDuration > 0) { m_closeTimer = startTimer(visibilityDuration * 1000); } }
void ChatLineModelItem::computeWrapList() const { QString text = _styledMsg.plainContents(); int length = text.length(); if (!length) return; QList<ChatLineModel::Word> wplist; // use a temp list which we'll later copy into a QVector for efficiency QTextBoundaryFinder finder(QTextBoundaryFinder::Line, _styledMsg.plainContents().unicode(), length, TextBoundaryFinderBuffer, TextBoundaryFinderBufferSize); int idx; int oldidx = 0; ChatLineModel::Word word; word.start = 0; qreal wordstartx = 0; QTextLayout layout(_styledMsg.plainContents()); QTextOption option; option.setWrapMode(QTextOption::NoWrap); layout.setTextOption(option); layout.setAdditionalFormats(QtUi::style()->toTextLayoutList(_styledMsg.contentsFormatList(), length, messageLabel())); layout.beginLayout(); QTextLine line = layout.createLine(); line.setNumColumns(length); layout.endLayout(); while ((idx = finder.toNextBoundary()) >= 0 && idx <= length) { // QTextBoundaryFinder has inconsistent behavior in Qt version up to and including 4.6.3 (at least). // It doesn't point to the position we should break, but to the character before that. // Unfortunately Qt decided to fix this by changing the behavior of QTBF, so now we have to add a version // check. At the time of this writing, I'm still trying to get this reverted upstream... // // cf. https://bugs.webkit.org/show_bug.cgi?id=31076 and Qt commit e6ac173 static int needWorkaround = -1; if (needWorkaround < 0) { needWorkaround = 0; QStringList versions = QString(qVersion()).split('.'); if (versions.count() == 3 && versions.at(0).toInt() == 4) { if (versions.at(1).toInt() <= 6 && versions.at(2).toInt() <= 3) needWorkaround = 1; } } if (needWorkaround == 1) { if (idx < length) idx++; } if (idx == oldidx) continue; word.start = oldidx; int wordend = idx; for (; wordend > word.start; wordend--) { if (!text.at(wordend-1).isSpace()) break; } qreal wordendx = line.cursorToX(wordend); qreal trailingendx = line.cursorToX(idx); word.endX = wordendx; word.width = wordendx - wordstartx; word.trailing = trailingendx - wordendx; wordstartx = trailingendx; wplist.append(word); oldidx = idx; } // A QVector needs less space than a QList _wrapList.resize(wplist.count()); for (int i = 0; i < wplist.count(); i++) { _wrapList[i] = wplist.at(i); } }
QVariant ChatLineModelItem::backgroundBrush(UiStyle::FormatType subelement, bool selected) const { QTextCharFormat fmt = QtUi::style()->format(UiStyle::formatType(_styledMsg.type()) | subelement, messageLabel() | (selected ? UiStyle::Selected : 0)); if (fmt.hasProperty(QTextFormat::BackgroundBrush)) return QVariant::fromValue<QBrush>(fmt.background()); return QVariant(); }
void AlterTable::on_actionAgregar_Columna_triggered() { QDialog dialog(this); dialog.setWindowTitle("Agregar"); QLabel messageLabel("Nombre de Columna:", &dialog); QLineEdit columnNameLineEdit(&dialog); QLabel typeLabel("Tipo:"); QComboBox typeComboBox(&dialog); typeComboBox.addItems(QStringList() << "TINYINT" << "SMALLINT" << "MEDIUMINT" << "INT" << "BIGINT" << "BIT" << "FLOAT" << "DOUBLE" << "DECIMAL" << "CHAR" << "VARCHAR" << "TINYTEXT" << "TEXT" << "MEDIUMTEXT" << "LONGTEXT" << "BINARY" << "VARBINARY" << "TINYBLOB" << "BLOB" << "MEDIUMBLOB" << "LONGBLOB" << "DATE" << "TIME" << "YEAR" << "DATETIME" << "TIMESTAMP" << "POINT" << "LINESTRING" << "POLYGON" << "GEOMETRY" << "MULTIPOINT" << "MULTILINESTRING" << "MULTIPOLYGON" << "GEOMETRYCOLLECTION" << "ENUM" << "SET"); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(&messageLabel); layout->addWidget(&columnNameLineEdit); layout->addWidget(&typeLabel); layout->addWidget(&typeComboBox); QPushButton addPushButton("Agregar", &dialog); QPushButton cancelPushButton("Cancelar", &dialog); connect(&addPushButton, SIGNAL(clicked()), &dialog, SLOT(accept())); connect(&cancelPushButton, SIGNAL(clicked()), &dialog, SLOT(reject())); QHBoxLayout *buttonsLayout = new QHBoxLayout; buttonsLayout->addWidget(&addPushButton); buttonsLayout->addWidget(&cancelPushButton); layout->addLayout(buttonsLayout); dialog.setLayout(layout); if (dialog.exec() == QDialog::Rejected) { return; } int lenght = 0; if (typeComboBox.currentText() == "VARCHAR" || typeComboBox.currentText() == "VARBINARY") { QInputDialog inDialog(&dialog); inDialog.setWindowTitle("Longitud"); inDialog.setLabelText("Longitud:"); inDialog.setInputMode(QInputDialog::IntInput); if (inDialog.exec() == QInputDialog::Rejected) { return; } lenght = inDialog.intValue(); } QDialog configurationDialog(&dialog); configurationDialog.setWindowTitle("Configuración"); QRadioButton afterOfRadioButton("Despues de", &configurationDialog); QRadioButton lastRadioButton("Al Final", &configurationDialog); lastRadioButton.setChecked(true); QVBoxLayout *layoutConf = new QVBoxLayout; QPushButton acceptPushButton("Aceptar", &configurationDialog); QPushButton cancelConfPushButton("Cancelar", &configurationDialog); connect(&acceptPushButton, SIGNAL(clicked()), &configurationDialog, SLOT(accept())); connect(&cancelConfPushButton, SIGNAL(clicked()), &configurationDialog, SLOT(reject())); layoutConf->addWidget(&afterOfRadioButton); layoutConf->addWidget(&lastRadioButton); QHBoxLayout *buttonsConfLayout = new QHBoxLayout; buttonsConfLayout->addWidget(&acceptPushButton); buttonsConfLayout->addWidget(&cancelConfPushButton); layoutConf->addLayout(buttonsConfLayout); configurationDialog.setLayout(layoutConf); if (configurationDialog.exec() == QDialog::Rejected) { return; } QString afterOfString = QString(); if (afterOfRadioButton.isChecked()) { QInputDialog inDialog(&configurationDialog); inDialog.setWindowTitle("Referencia"); inDialog.setLabelText("Columna:"); if (inDialog.exec() == QInputDialog::Rejected) { QMessageBox mBox(this); mBox.setWindowTitle("ERROR"); mBox.setIcon(QMessageBox::Critical); mBox.setText( "No se puede continuar con la operación de agregado"); mBox.exec(); return; } afterOfString = inDialog.textValue(); } QString queryString = "ALTER TABLE " + tableName + " ADD COLUMN " + columnNameLineEdit.text() + " " + typeComboBox.currentText(); if (typeComboBox.currentText() == "VARCHAR" || typeComboBox.currentText() == "VARBINARY") { queryString += "(" + QString::number(lenght) + ")"; } if (afterOfRadioButton.isChecked()) { queryString += " AFTER " + afterOfString; } queryString += ";"; QSqlQuery query(*db); query.exec(queryString); if (query.lastError().isValid()) { QMessageBox mBox(this); mBox.setWindowTitle("ERROR"); mBox.setIcon(QMessageBox::Critical); mBox.setText("No se puede realizar la operación de agregado"); mBox.exec(); return; } QString strQuery; if (engineName == "sqlite") { strQuery = QString("PRAGMA table_info(%1)").arg(tableName); } else if (engineName == "mysql") { strQuery = QString("SHOW COLUMNS FROM %1").arg(tableName); } queryModel->setQuery(strQuery); counterOfColumns->setText(QString::number(queryModel->rowCount())); }
void AlterTable::on_actionModificar_Columna_triggered() { QDialog dialog(this); dialog.setWindowTitle("Modificar Columna"); QRadioButton isNullableRadioButton("Puede ser Nulo", &dialog); QRadioButton isNotNullableRadioButton("No puede ser Nulo", &dialog); isNullableRadioButton.setChecked(true); QLabel messageLabel("Nombre de Columna", &dialog); QLineEdit columnNameLineEdit(&dialog); QLabel typeLabel("Tipo", &dialog); QComboBox typeComboBox(&dialog); typeComboBox.addItems(QStringList() << "TINYINT" << "SMALLINT" << "MEDIUMINT" << "INT" << "BIGINT" << "BIT" << "FLOAT" << "DOUBLE" << "DECIMAL" << "CHAR" << "VARCHAR" << "TINYTEXT" << "TEXT" << "MEDIUMTEXT" << "LONGTEXT" << "BINARY" << "VARBINARY" << "TINYBLOB" << "BLOB" << "MEDIUMBLOB" << "LONGBLOB" << "DATE" << "TIME" << "YEAR" << "DATETIME" << "TIMESTAMP" << "POINT" << "LINESTRING" << "POLYGON" << "GEOMETRY" << "MULTIPOINT" << "MULTILINESTRING" << "MULTIPOLYGON" << "GEOMETRYCOLLECTION" << "ENUM" << "SET"); QPushButton acceptPushButton("Aceptar", &dialog); QPushButton cancelPushButton("Cancelar", &dialog); connect(&acceptPushButton, SIGNAL(clicked()), &dialog, SLOT(accept())); connect(&cancelPushButton, SIGNAL(clicked()), &dialog, SLOT(reject())); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(&isNullableRadioButton); layout->addWidget(&isNotNullableRadioButton); layout->addWidget(&messageLabel); layout->addWidget(&columnNameLineEdit); layout->addWidget(&typeLabel); layout->addWidget(&typeComboBox); QHBoxLayout *buttonsLayout = new QHBoxLayout; buttonsLayout->addWidget(&acceptPushButton); buttonsLayout->addWidget(&cancelPushButton); layout->addLayout(buttonsLayout); dialog.setLayout(layout); if (dialog.exec() == QDialog::Rejected) { return; } if (columnNameLineEdit.text() == QString()) { QMessageBox mBox(this); mBox.setWindowTitle("ERROR"); mBox.setIcon(QMessageBox::Critical); mBox.setText( "No se puede realizar la operación de modificación"); mBox.exec(); return; } QString lenghtString = QString(); if (typeComboBox.currentText() == "VARCHAR" || typeComboBox.currentText() == "VARBINARY") { QDialog lenDialog(&dialog); lenDialog.setWindowTitle("Longitud"); QVBoxLayout *layout = new QVBoxLayout; QHBoxLayout *topLayout = new QHBoxLayout; topLayout->addWidget(new QLabel("Longitud:", &lenDialog)); QLineEdit lenValueText(&lenDialog); topLayout->addWidget(&lenValueText); QHBoxLayout *layoutButtons = new QHBoxLayout; QPushButton okButton("Aceptar", &lenDialog); QPushButton cancelButton("Cancelar", &lenDialog); layoutButtons->addWidget(&okButton); layoutButtons->addWidget(&cancelButton); layout->addLayout(topLayout); layout->addLayout(layoutButtons); lenDialog.setLayout(layout); connect(&okButton, SIGNAL(clicked()), &lenDialog, SLOT(accept())); connect(&cancelButton, SIGNAL(clicked()), &lenDialog, SLOT(reject())); if (lenDialog.exec() == QDialog::Rejected) { QMessageBox mBox; mBox.setWindowTitle("ERROR"); mBox.setIcon(QMessageBox::Critical); mBox.setText( "No se puede continuar con la operación de modificación"); mBox.exec(); return; } lenghtString = "(" + lenValueText.text() + ")"; } QString isNullString = QString(); if (isNotNullableRadioButton.isChecked()) { isNullString = "NOT NULL"; } QSqlQuery query(*db); query.exec("ALTER TABLE " + tableName + " CHANGE COLUMN " + columnNameLineEdit.text() + " " + columnNameLineEdit.text() + " " + typeComboBox.currentText() + lenghtString + " " + isNullString + ";"); QString strQuery; if (engineName == "sqlite") { strQuery = QString("PRAGMA table_info(%1)").arg(tableName); } else if (engineName == "mysql") { strQuery = QString("SHOW COLUMNS FROM %1").arg(tableName); } queryModel->setQuery(strQuery); }