QList<int> QFormatConfig::modifiedFormats() const { QList<int> hasModif; if ( m_currentScheme ) { const int n = m_currentScheme->formatCount(); m_table->setRowCount(n); for ( int i = 0 ; i < n; ++i ) { QString fid = m_currentScheme->id(i); QFormat& fmt = m_currentScheme->formatRef(i); QTableWidgetItem *item; item = m_table->item(i, 1); if ( fmt.weight != (item->checkState() == Qt::Checked ? QFont::Bold : QFont::Normal) ) { hasModif << i; continue; } item = m_table->item(i, 2); if ( fmt.italic != (item->checkState() == Qt::Checked) ) { hasModif << i; continue; } item = m_table->item(i, 3); if ( fmt.underline != (item->checkState() == Qt::Checked) ) { hasModif << i; continue; } item = m_table->item(i, 4); if ( fmt.overline != (item->checkState() == Qt::Checked) ) { hasModif << i; continue; } item = m_table->item(i, 5); if ( fmt.strikeout != (item->checkState() == Qt::Checked) ) { hasModif << i; continue; } item = m_table->item(i, 6); if ( fmt.waveUnderline != (item->checkState() == Qt::Checked) ) { hasModif << i; continue; } QSimpleColorPicker *cp; cp = qobject_cast<QSimpleColorPicker*>(m_table->cellWidget(i, 7)); if ( cp && fmt.foreground != cp->color() ) { hasModif << i; continue; } cp = qobject_cast<QSimpleColorPicker*>(m_table->cellWidget(i, 8)); if ( cp && fmt.background != cp->color() ) { hasModif << i; continue; } cp = qobject_cast<QSimpleColorPicker*>(m_table->cellWidget(i, 9)); if ( cp && fmt.linescolor != cp->color() ) { hasModif << i; continue; } } } return hasModif; }
QList<int> QFormatConfig::modifiedFormats() const { QList<int> hasModif; if ( m_currentScheme ) { const int n = m_currentScheme->formatCount(); m_table->setRowCount(n); for ( int i = 0 ; i < n; ++i ) { QString fid = m_currentScheme->id(i); QFormat& fmt = m_currentScheme->formatRef(i); QTableWidgetItem *item; item = m_table->item(i, 1); if ( fmt.weight != (item->checkState() == Qt::Checked ? QFont::Bold : QFont::Normal) ) { hasModif << i; continue; } item = m_table->item(i, 2); if ( fmt.italic != (item->checkState() == Qt::Checked) ) { hasModif << i; continue; } item = m_table->item(i, 3); if ( fmt.underline != (item->checkState() == Qt::Checked) ) { hasModif << i; continue; } item = m_table->item(i, 4); if ( fmt.overline != (item->checkState() == Qt::Checked) ) { hasModif << i; continue; } item = m_table->item(i, 5); if ( fmt.strikeout != (item->checkState() == Qt::Checked) ) { hasModif << i; continue; } item = m_table->item(i, 6); if ( fmt.waveUnderline != (item->checkState() == Qt::Checked) ) { hasModif << i; continue; } QSimpleColorPicker *cp; cp = qobject_cast<QSimpleColorPicker*>(m_table->cellWidget(i, 7)); if ( cp && fmt.foreground != cp->color() ) { hasModif << i; continue; } cp = qobject_cast<QSimpleColorPicker*>(m_table->cellWidget(i, 8)); if ( cp && fmt.background != cp->color() ) { hasModif << i; continue; } cp = qobject_cast<QSimpleColorPicker*>(m_table->cellWidget(i, 9)); if ( cp && fmt.linescolor != cp->color() ) { hasModif << i; continue; } QComboBox *fcb; //item = m_table->item(i, 10); fcb = qobject_cast<QComboBox*>(m_table->cellWidget(i, 10)); QString newFont=fcb->currentText()==tr("<default>") ? "" : fcb->currentText(); if (newFont != fmt.fontFamily){ hasModif << i; continue; } QDoubleSpinBox* sb= qobject_cast<QDoubleSpinBox*>(m_table->cellWidget(i, 11)); if (qRound(sb->value()/100.0*basePointSize) != fmt.pointSize && (qRound(sb->value()/100.0*basePointSize) != basePointSize || fmt.pointSize != 0)){ hasModif << i; continue; } QSpinBox* psb= qobject_cast<QSpinBox*>(m_table->cellWidget(i, 12)); if (psb->value() != fmt.priority) { hasModif << i; continue; } } } return hasModif; }
/*! \brief Apply changes made to the currently edited scheme, if any */ void QFormatConfig::apply() { if ( m_currentScheme ) { const int n = m_currentScheme->formatCount(); m_table->setRowCount(n); for ( int i = 0 ; i < n; ++i ) { QString fid = m_currentScheme->id(i); QFormat& fmt = m_currentScheme->formatRef(i); QTableWidgetItem *item; item = m_table->item(i, 1); fmt.weight = item->checkState() == Qt::Checked ? QFont::Bold : QFont::Normal; item = m_table->item(i, 2); fmt.italic = item->checkState() == Qt::Checked; item = m_table->item(i, 3); fmt.underline = item->checkState() == Qt::Checked; item = m_table->item(i, 4); fmt.overline = item->checkState() == Qt::Checked; item = m_table->item(i, 5); fmt.strikeout = item->checkState() == Qt::Checked; item = m_table->item(i, 6); fmt.waveUnderline = item->checkState() == Qt::Checked; QSimpleColorPicker *cp; cp = qobject_cast<QSimpleColorPicker*>(m_table->cellWidget(i, 7)); if ( cp ) fmt.foreground = cp->color(); cp = qobject_cast<QSimpleColorPicker*>(m_table->cellWidget(i, 8)); if ( cp ) fmt.background = cp->color(); cp = qobject_cast<QSimpleColorPicker*>(m_table->cellWidget(i, 9)); if ( cp ) fmt.linescolor = cp->color(); } // TODO : save scheme and update editors // this will only save schemes loaded from an existing file m_currentScheme->save(); if ( m_autonomous ) { QList<QEditor*> editors = QEditor::editors(); foreach ( QEditor *e, editors ) { if ( e->document()->formatScheme() == m_currentScheme ) e->viewport()->update(); } } } }
/*! \brief Apply changes made to the currently edited scheme, if any */ void QFormatConfig::apply() { if ( m_currentScheme ) { for ( int i = 0 ; i < m_table->rowCount(); ++i ) { QTableWidgetItem *item = m_table->item(i,0); if (!item) continue; QString fid = item->data(Qt::UserRole).toString(); if (fid == "") continue; QFormat fmt = m_currentScheme->format(fid); item = m_table->item(i, 1); fmt.weight = item->checkState() == Qt::Checked ? QFont::Bold : QFont::Normal; item = m_table->item(i, 2); fmt.italic = item->checkState() == Qt::Checked; item = m_table->item(i, 3); fmt.underline = item->checkState() == Qt::Checked; item = m_table->item(i, 4); fmt.overline = item->checkState() == Qt::Checked; item = m_table->item(i, 5); fmt.strikeout = item->checkState() == Qt::Checked; item = m_table->item(i, 6); fmt.waveUnderline = item->checkState() == Qt::Checked; QSimpleColorPicker *cp; cp = qobject_cast<QSimpleColorPicker*>(m_table->cellWidget(i, 7)); if ( cp ) fmt.foreground = cp->color(); cp = qobject_cast<QSimpleColorPicker*>(m_table->cellWidget(i, 8)); fmt.background = cp->color(); cp = qobject_cast<QSimpleColorPicker*>(m_table->cellWidget(i, 9)); if ( cp ) fmt.linescolor = cp->color(); QComboBox *fcb; fcb = qobject_cast<QComboBox*>(m_table->cellWidget(i, 10)); fmt.fontFamily = fcb->currentText()==tr("<default>") ? "" : fcb->currentText(); QDoubleSpinBox* sb= qobject_cast<QDoubleSpinBox*>(m_table->cellWidget(i, 11)); int newSize = qRound(sb->value()/100.0*basePointSize); if (newSize == basePointSize) fmt.pointSize = 0; else fmt.pointSize = newSize; QSpinBox* psb= qobject_cast<QSpinBox*>(m_table->cellWidget(i, 12)); fmt.setPriority(psb->value()); m_currentScheme->setFormat(fid, fmt); } // TODO : save scheme and update editors // this will only save schemes loaded from an existing file m_currentScheme->save(); if ( m_autonomous ) { QList<QEditor*> editors = QEditor::editors(); foreach ( QEditor *e, editors ) { if ( e->document()->formatScheme() == m_currentScheme ) e->viewport()->update(); } } } }