void QuotesTableView::updateStyles()
{
    QTableView::updateGeometries();

    QHeaderView* hdr = horizontalHeader();
    if( !hdr ) return;

    hdr->setFont( *Global::native );
    hdr->setStretchLastSection(true);
}
Beispiel #2
0
ByteTableView::ByteTableView( ByteTableTool *tool, QWidget* parent )
  : AbstractToolWidget( parent ),
    mTool( tool )
{
    QVBoxLayout *baseLayout = new QVBoxLayout( this );
    baseLayout->setMargin( 0 );

    mByteTableView = new QTreeView( this );
    // TODO: find a signal/event emitted when fixedfont changes
//     connect( KGlobalSettings::self(), &KGlobalSettings::kdisplayFontChanged,
//              this, &ByteTableView::setFixedFontByGlobalSettings );
//     connect( KGlobalSettings::self(), &KGlobalSettings::kdisplayFontChanged,
//              this, &ByteTableView::resizeColumnsWidth );
//     connect( KGlobalSettings::self(), &KGlobalSettings::kdisplayStyleChanged,
//              this, &ByteTableView::resizeColumnsWidth );
    setFixedFontByGlobalSettings(); //do this before setting model
    mByteTableView->setObjectName( QStringLiteral( "ByteTable" ) );
    mByteTableView->setRootIsDecorated( false );
    mByteTableView->setItemsExpandable( false );
    mByteTableView->setUniformRowHeights( true );
    mByteTableView->setAllColumnsShowFocus( true );
    mByteTableView->setSortingEnabled( false );
    QHeaderView* header = mByteTableView->header();
    header->setFont( font() );
    header->setSectionResizeMode( QHeaderView::Interactive );
    header->setStretchLastSection( false );
    mByteTableView->setModel( mTool->byteTableModel() );
    connect( mByteTableView, &QTreeView::doubleClicked,
             this, &ByteTableView::onDoubleClicked );

    baseLayout->addWidget( mByteTableView, 10 );

    QHBoxLayout *insertLayout = new QHBoxLayout();

    QLabel *label = new QLabel( i18nc("@label:spinbox number of bytes to insert","Number (bytes):"), this );
    insertLayout->addWidget( label );

    mInsertCountEdit = new QSpinBox( this );
    mInsertCountEdit->setRange( 1, INT_MAX );
    mInsertCountEdit->setValue( 1 );
    label->setBuddy( mInsertCountEdit );
    insertLayout->addWidget( mInsertCountEdit );
    const QString insertCountToolTip =
        i18nc( "@info:tooltip",
               "Number of repeats of the currently selected byte in the table to be inserted." );
    label->setToolTip( insertCountToolTip );
    mInsertCountEdit->setToolTip( insertCountToolTip );

    insertLayout->addStretch();

    mInsertButton = new QPushButton( this );
    KGuiItem::assign( mInsertButton, KStandardGuiItem::insert() );
    mInsertButton->setEnabled( mTool->hasWriteable() );
    connect( mTool, &ByteTableTool::hasWriteableChanged, mInsertButton, &QPushButton::setEnabled );
    connect( mInsertButton, &QPushButton::clicked, this, &ByteTableView::onInsertClicked );
    const QString insertButtonToolTip =
        i18nc( "@info:tooltip",
               "Insert the currently selected byte in the table repeated the given number of times." );
    mInsertButton->setToolTip( insertButtonToolTip );
    addButton( mInsertButton, AbstractToolWidget::Default );
    insertLayout->addWidget( mInsertButton );

    baseLayout->addLayout( insertLayout );
    
    //if nothing has changed reuse the old values. This means the bytetable is fully constructed
    //after ~3ms and not 800 as it was before. If the saved values can not be reused it takes ~100ms
    const QList<int> columnsWidth = ByteTableViewSettings::columnsWidth();
    const QString styleName = QApplication::style()->objectName();
    const QString fixedFontData = QFontDatabase::systemFont(QFontDatabase::FixedFont).toString();
    if ( columnsWidth.size() < ByteTableModel::NoOfIds || styleName != ByteTableViewSettings::style()
            || fixedFontData != ByteTableViewSettings::fixedFont() )
    {
        resizeColumnsWidth();
    }
    else 
    {
        for (int i = 0; i < ByteTableModel::NoOfIds; ++i) 
        {
            header->resizeSection( i, columnsWidth.at( i ) );
        }
    }
}