⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listvieweditorimpl.cpp

📁 Linux下的基于X11的图形开发环境。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/************************************************************************ Copyright (C) 2000 Trolltech AS.  All rights reserved.**** This file is part of Qt Designer.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "formwindow.h"#include "mainwindow.h"#include "listvieweditorimpl.h"#include "pixmapchooser.h"#include "command.h"#include "listviewdnd.h"#include "listboxdnd.h"#include "listboxrename.h"#include <qlistview.h>#include <qheader.h>#include <qlistbox.h>#include <qlineedit.h>#include <qcheckbox.h>#include <qlabel.h>#include <qtabwidget.h>#include <qspinbox.h>#include <qpushbutton.h>#include <qptrstack.h>ListViewEditor::ListViewEditor( QWidget *parent, QListView *lv, FormWindow *fw )    : ListViewEditorBase( parent, 0, TRUE ), listview( lv ), formwindow( fw ){    connect( helpButton, SIGNAL( clicked() ), MainWindow::self, SLOT( showDialogHelp() ) );    itemText->setEnabled( FALSE );    itemChoosePixmap->setEnabled( FALSE );    itemDeletePixmap->setEnabled( FALSE );    itemColumn->setEnabled( FALSE );    setupColumns();    PopulateListViewCommand::transferItems( listview, itemsPreview );    setupItems();    itemsPreview->setShowSortIndicator( listview->showSortIndicator() );    itemsPreview->setAllColumnsShowFocus( listview->allColumnsShowFocus() );    itemsPreview->setRootIsDecorated( listview->rootIsDecorated() );    if ( itemsPreview->firstChild() ) {	itemsPreview->setCurrentItem( itemsPreview->firstChild() );	itemsPreview->setSelected( itemsPreview->firstChild(), TRUE );    }    // Clamp on drag and drop to QListView    ListViewDnd *itemsDnd = new ListViewDnd( itemsPreview );    itemsDnd->setDragMode( ListViewDnd::Internal | ListViewDnd::Move );    QObject::connect( itemsDnd, SIGNAL( dropped( QListViewItem * ) ),		      itemsDnd, SLOT( confirmDrop( QListViewItem * ) ) );    // Enable rename for all QListViewItems    QListViewItemIterator it = ((QListView *)itemsPreview)->firstChild();    for ( ; *it; it++ )	(*it)->setRenameEnabled( 0, TRUE );    // Connect listview signal to signal-relay    QObject::connect( itemsPreview,		      SIGNAL( itemRenamed( QListViewItem*, int, const QString & ) ),		      this,		      SLOT( emitItemRenamed(QListViewItem*, int, const QString&) ) );    // Connect signal-relay to QLineEdit "itemText"    QObjectList *l = parent->queryList( "QLineEdit", "itemText" );    QObject *obj;    QObjectListIt itemsLineEditIt( *l );    while ( (obj = itemsLineEditIt.current()) != 0 ) {        ++itemsLineEditIt;	QObject::connect( this,			  SIGNAL( itemRenamed( const QString & ) ),			  obj,			  SLOT( setText( const QString & ) ) );    }    delete l;    // Clamp on drag and drop to QListBox    ListBoxDnd *columnsDnd = new ListBoxDnd( colPreview );    columnsDnd->setDragMode( ListBoxDnd::Internal | ListBoxDnd::Move );    QObject::connect( columnsDnd, SIGNAL( dropped( QListBoxItem * ) ),		      columnsDnd, SLOT( confirmDrop( QListBoxItem * ) ) );    // Clamp on rename to QListBox    ListBoxRename *columnsRename = new ListBoxRename( colPreview );    QObject::connect( columnsRename,		      SIGNAL( itemTextChanged( const QString & ) ),		      this,		      SLOT( columnTextChanged( const QString & ) ) );    // Find QLineEdit "colText" and connect    l = parent->queryList( "QLineEdit", "colText" );    QObjectListIt columnsLineEditIt( *l );    while ( (obj = columnsLineEditIt.current()) != 0 ) {        ++columnsLineEditIt;	QObject::connect( columnsRename,			  SIGNAL( itemTextChanged( const QString & ) ),			  obj,			  SLOT( setText( const QString & ) ) );    }    delete l;}void ListViewEditor::applyClicked(){    setupItems();    PopulateListViewCommand *cmd = new PopulateListViewCommand( tr( "Edit the Items and Columns of '%1'" ).arg( listview->name() ),								formwindow, listview, itemsPreview );    cmd->execute();    formwindow->commandHistory()->addCommand( cmd );}void ListViewEditor::okClicked(){    applyClicked();    accept();}void ListViewEditor::columnClickable( bool b ){    Column *c = findColumn( colPreview->item( colPreview->currentItem() ) );    if ( !c )	return;    c->clickable = b;}void ListViewEditor::columnDownClicked(){    if ( colPreview->currentItem() == -1 ||	 colPreview->currentItem() > (int)colPreview->count() - 2 )	return;    colPreview->clearSelection();    QListBoxItem *i = colPreview->item( colPreview->currentItem() );    QListBoxItem *below = i->next();    colPreview->takeItem( i );    colPreview->insertItem( i, below );    colPreview->setCurrentItem( i );    colPreview->setSelected( i, TRUE );}void ListViewEditor::columnPixmapChosen(){    Column *c = findColumn( colPreview->item( colPreview->currentItem() ) );    if ( !c )	return;    QPixmap pix;    if ( colPixmap->pixmap() )	pix = qChoosePixmap( this, formwindow, *colPixmap->pixmap() );    else	pix = qChoosePixmap( this, formwindow, QPixmap() );    if ( pix.isNull() )	return;    c->pixmap = pix;    colPreview->blockSignals( TRUE );    if ( !c->pixmap.isNull() )	colPreview->changeItem( c->pixmap, c->text, colPreview->index( c->item ) );    else	colPreview->changeItem( c->text, colPreview->index( c->item ) );    c->item = colPreview->item( colPreview->currentItem() );    colPixmap->setPixmap( c->pixmap );    colPreview->blockSignals( FALSE );    colDeletePixmap->setEnabled( TRUE );}void ListViewEditor::columnPixmapDeleted(){    Column *c = findColumn( colPreview->item( colPreview->currentItem() ) );    if ( !c )	return;    c->pixmap = QPixmap();    colPreview->blockSignals( TRUE );    if ( !c->pixmap.isNull() )	colPreview->changeItem( c->pixmap, c->text, colPreview->index( c->item ) );    else	colPreview->changeItem( c->text, colPreview->index( c->item ) );    c->item = colPreview->item( colPreview->currentItem() );    colPixmap->setText( "" );    colPreview->blockSignals( FALSE );    colDeletePixmap->setEnabled( FALSE );}void ListViewEditor::columnResizable( bool b ){    Column *c = findColumn( colPreview->item( colPreview->currentItem() ) );    if ( !c )	return;    c->resizable = b;}void ListViewEditor::columnTextChanged( const QString &txt ){    Column *c = findColumn( colPreview->item( colPreview->currentItem() ) );    if ( !c )	return;    c->text = txt;    colPreview->blockSignals( TRUE );    if ( !c->pixmap.isNull() )	colPreview->changeItem( c->pixmap, c->text, colPreview->index( c->item ) );    else	colPreview->changeItem( c->text, colPreview->index( c->item ) );    c->item = colPreview->item( colPreview->currentItem() );    colPreview->blockSignals( FALSE );}void ListViewEditor::columnUpClicked(){    if ( colPreview->currentItem() <= 0 )	return;    colPreview->clearSelection();    QListBoxItem *i = colPreview->item( colPreview->currentItem() );    QListBoxItem *above = i->prev();    colPreview->takeItem( above );    colPreview->insertItem( above, i );    colPreview->setCurrentItem( i );    colPreview->setSelected( i, TRUE );}void ListViewEditor::currentColumnChanged( QListBoxItem *i ){    Column *c = findColumn( i );    if ( !i || !c ) {	colText->setEnabled( FALSE );	colPixmap->setEnabled( FALSE );	colDeletePixmap->setEnabled( FALSE );	colText->blockSignals( TRUE );	colText->setText( "" );	colText->blockSignals( FALSE );	colClickable->setEnabled( FALSE );	colResizable->setEnabled( FALSE );	return;    }    colText->setEnabled( TRUE );    colPixmap->setEnabled( TRUE );    colDeletePixmap->setEnabled( i->pixmap() && !i->pixmap()->isNull() );    colClickable->setEnabled( TRUE );    colResizable->setEnabled( TRUE );    colText->blockSignals( TRUE );    colText->setText( c->text );    colText->blockSignals( FALSE );    if ( !c->pixmap.isNull() )	colPixmap->setPixmap( c->pixmap );    else	colPixmap->setText( "" );    colClickable->setChecked( c->clickable );    colResizable->setChecked( c->resizable );}void ListViewEditor::newColumnClicked(){    Column col;    col.text = tr( "New Column" );    col.pixmap = QPixmap();    col.clickable = TRUE;    col.resizable = TRUE;    if ( !col.pixmap.isNull() )	col.item = new QListBoxPixmap( colPreview, col.pixmap, col.text );    else	col.item = new QListBoxText( colPreview, col.text );    columns.append( col );    colPreview->setCurrentItem( col.item );    colPreview->setSelected( col.item, TRUE );}void ListViewEditor::deleteColumnClicked(){    QListBoxItem *i = colPreview->item( colPreview->currentItem() );    if ( !i )	return;    for ( QValueList<Column>::Iterator it = columns.begin(); it != columns.end(); ++it ) {	if ( ( *it ).item == i ) {	    delete (*it).item;	    columns.remove( it );	    break;	}    }    if ( colPreview->currentItem() != -1 )	colPreview->setSelected( colPreview->currentItem(), TRUE );}void ListViewEditor::currentItemChanged( QListViewItem *i ){    if ( !i ) {	itemText->setEnabled( FALSE );	itemChoosePixmap->setEnabled( FALSE );	itemDeletePixmap->setEnabled( FALSE );	itemColumn->setEnabled( FALSE );	return;    }    itemText->setEnabled( TRUE );    itemChoosePixmap->setEnabled( TRUE );    itemDeletePixmap->setEnabled( i->pixmap( itemColumn->value() ) &&

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -