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

📄 createsmileywindow.cpp

📁 linux下的eva源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************** *   Copyright (C) 2006 by yunfan                                          * *   yunfan_zg@163.com                                                     * *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * *   This program is distributed in the hope that it will be useful,       * *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * *   GNU General Public License for more details.                          * *                                                                         * *   You should have received a copy of the GNU General Public License     * *   along with this program; if not, write to the                         * *   Free Software Foundation, Inc.,                                       * *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * ***************************************************************************/#include "createsmileywindow.h"#include "evausersetting.h"#include "evauser.h"#include "../evamain.h"#include "evaqtutil.h"#include <qlabel.h>#include <qpushbutton.h>#include <qcombobox.h>#include <qlineedit.h>#include <qdir.h>#include <qlistview.h>#include <qtoolbutton.h>#include <qlayout.h>#include <qradiobutton.h>#include <qtable.h>#include <qpopupmenu.h>#include <qimage.h>#include <qpixmap.h>#include <qmovie.h>#include <kfiledialog.h>#include <kmessagebox.h>#include <klocale.h>CreateSmileyWindow::CreateSmileyWindow( const QString & url, const int groupIndex )	: m_FileName(url),	m_MultiFiles(false),	m_Config(0),	m_DefaultGroup(groupIndex){	init();}CreateSmileyWindow::~ CreateSmileyWindow( ){	if(m_Config) delete m_Config;}void CreateSmileyWindow::init( ){	if(!m_FileName.isEmpty()){		QString file = m_FileName.right( m_FileName.length() - m_FileName.findRev("/") - 1);		lblSelect->setText(file);		btnSelect->setEnabled(false);		leShortcut->setText(file.left(6));				leTip->setText(file.left( file.findRev(".") ) );	}	QString dir = EvaMain::user->getSetting()->getCustomSmileyDir() + "/";	m_Config = new CustomFaceConfig(dir);	if(m_Config->loadXML()){		QStringList groups = m_Config->groupNames();		cbbGroup->insertStringList(m_Config->groupNames());	}	cbbGroup->setCurrentItem(m_DefaultGroup);	connect(btnOK, SIGNAL(clicked()), this, SLOT(slotOKClicked() ));	connect(btnCancel, SIGNAL(clicked()), this, SLOT(close()));	connect(btnSelect, SIGNAL(clicked()), this, SLOT(slotSelectImagesClicked() ));}void CreateSmileyWindow::closeEvent( QCloseEvent * e ){	e->accept();	deleteLater();}void CreateSmileyWindow::slotSelectImagesClicked( ){	QString startDir =  QDir::homeDirPath();	QStringList fileNames = KFileDialog::getOpenFileNames(startDir,			"*.png *.bmp *.jpg *.jpeg *.gif |" + i18n(" all images (*.png *.bmp *.jpg *.jpeg *.gif)"), this, 			i18n("select image file(s)"));	if(fileNames.count() == 1){		m_FileName = fileNames[0];		QString file = m_FileName.right( m_FileName.length() - m_FileName.findRev("/") - 1);		lblSelect->setText(file);		leShortcut->setEnabled( true);		leShortcut->setText(file.left(6));		leTip->setEnabled( true );		leTip->setText(file.left( file.findRev(".") ) );	}else{		m_MultiFiles = true;		lblSelect->setText(i18n("Multi-Files Selected."));		m_FileNames = fileNames;		leShortcut->setText("");		leTip->setText("");		leShortcut->setEnabled( false);		leTip->setEnabled( false);	}}void CreateSmileyWindow::slotOKClicked( ){	bool ok = false;	QString destDir = EvaMain::user->getSetting()->getCustomSmileyDir();	if(cbbGroup->currentItem()>0)		destDir += ( "/" + cbbGroup->currentText() );	if(!m_FileName.isEmpty()){ 		QString destFile = EvaHelper::generateCustomSmiley(m_FileName, destDir, true); 		if(!destFile.isEmpty()) {			QString name = destFile.right( destFile.length() - destFile.findRev("/") - 1);			CustomFace face(name, leShortcut->text(), leTip->text(), 0, cbbGroup->currentItem());			ok = m_Config->addFace(face);		}	} else {		///TODO: add multiple files		for(QStringList::Iterator it = m_FileNames.begin(); it != m_FileNames.end(); ++it){			QString destFile = EvaHelper::generateCustomSmiley((*it), destDir, true);			if(!destFile.isEmpty()) {				QString name = destFile.right( destFile.length() - destFile.findRev("/") - 1);				CustomFace face( name, name.left(6), name.left(name.findRev(".")), 0, cbbGroup->currentItem());				ok = m_Config->addFace(face);			}		}	}	if(ok) m_Config->saveXML();	emit addCustomSmileyReady(ok);	close();}/**======================================================*/RmSmileyGroupDialog::RmSmileyGroupDialog(  int indexOfRm, CustomFaceConfig *config, QWidget* parent, const char* name, bool modal, WFlags fl )    : QDialog( parent, name, modal, fl ), m_IndexOfRm(indexOfRm), m_Config(config){	if ( !name )		setName( "RmSmileyGroupUI" );	RmSmileyGroupUILayout = new QGridLayout( this, 1, 1, 16, 7, "RmSmileyGroupUILayout"); 		layout3 = new QHBoxLayout( 0, 0, 6, "layout3"); 	spacer3 = new QSpacerItem( 81, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );	layout3->addItem( spacer3 );		btnOK = new QPushButton( this, "btnOK" );	layout3->addWidget( btnOK );		btnCancel = new QPushButton( this, "btnCancel" );	layout3->addWidget( btnCancel );		RmSmileyGroupUILayout->addLayout( layout3, 1, 0 );		layout7 = new QVBoxLayout( 0, 6, 15, "layout7"); 		rbtnRmAll = new QRadioButton( this, "rbtnRmAll" );	layout7->addWidget( rbtnRmAll );		layout6 = new QVBoxLayout( 0, 0, 6, "layout6"); 		rbtnRmMv = new QRadioButton( this, "rbtnRmMv" );	layout6->addWidget( rbtnRmMv );		layout4 = new QHBoxLayout( 0, 0, 6, "layout4"); 	spacer4 = new QSpacerItem( 20, 20, QSizePolicy::Fixed, QSizePolicy::Minimum );	layout4->addItem( spacer4 );		lblGroupTip = new QLabel( this, "lblGroupTip" );	layout4->addWidget( lblGroupTip );		cbbGroups = new QComboBox( FALSE, this, "cbbGroups" );	layout4->addWidget( cbbGroups );	layout6->addLayout( layout4 );	layout7->addLayout( layout6 );		RmSmileyGroupUILayout->addLayout( layout7, 0, 0 );	languageChange();	resize( QSize(309, 171).expandedTo(minimumSizeHint()) );	clearWState( WState_Polished );	// make remove all smileys in this group as the default	rbtnRmAll->setChecked( true);	rbtnRmMv->setChecked( false );	// setup combo box	QString dir = EvaMain::user->getSetting()->getCustomSmileyDir() + "/";	m_Config = new CustomFaceConfig(dir);	if(m_Config->loadXML()){		QStringList groups = m_Config->groupNames();		for( int i=0; i < (int)(groups.count()); i++){			if(i != m_IndexOfRm )  // ignore the group we are operating on				cbbGroups->insertItem(groups[i]);		}	}	cbbGroups->setCurrentItem(0);	m_Result = -2;		connect(rbtnRmAll, SIGNAL(clicked()), this, SLOT(slotRmAllClicked()));	connect(rbtnRmMv, SIGNAL(clicked()), this, SLOT(slotRmMvClicked()));	connect(btnOK, SIGNAL(clicked()), this, SLOT(slotOKClicked() ));	connect(btnCancel, SIGNAL(clicked()), this, SLOT(close()));}RmSmileyGroupDialog::~RmSmileyGroupDialog(){}void RmSmileyGroupDialog::languageChange(){	setCaption( i18n( "Remove Smiley Group" ) );	btnOK->setText( i18n( "&OK" ) );	btnOK->setAccel( QKeySequence( "Alt+O" ) );	btnCancel->setText( i18n( "&Cancel" ) );	btnCancel->setAccel( QKeySequence( "Alt+C" ) );	rbtnRmAll->setText( i18n( "Remove all smileys in this group" ) );	rbtnRmMv->setText( i18n( "Before removing this group," ) );	lblGroupTip->setText( i18n( "move all its smileys to:" ) );}void RmSmileyGroupDialog::slotRmAllClicked(){	rbtnRmAll->setChecked( true);	rbtnRmMv->setChecked( false );}void RmSmileyGroupDialog::slotRmMvClicked(){	rbtnRmAll->setChecked( false);	rbtnRmMv->setChecked( true );}void RmSmileyGroupDialog::slotOKClicked(){	if(rbtnRmAll->isChecked())		m_Result = -1;	else{		m_Result = cbbGroups->currentItem();		// as we ignored the group itself		if(m_Result >= m_IndexOfRm)			m_Result++;	}	close();}void RmSmileyGroupDialog::slotCancelClicked(){	m_Result = -2;}int RmSmileyGroupDialog::QueryDialog(int indexOfRm, CustomFaceConfig *config, QWidget* parent){	RmSmileyGroupDialog *dialog = new RmSmileyGroupDialog( indexOfRm, config, parent);	dialog->exec();	int result = dialog->m_Result;	delete dialog;	return result;}/**======================================================*/class CustomItem : public QTableItem{public:	CustomItem(QTable *table, const QString &text)		: QTableItem(table, QTableItem::OnTyping, text )	{	}		CustomItem(QTable *table, const QString &text, const QPixmap &p )		: QTableItem(table, QTableItem::OnTyping, text, p)	{	}		virtual int alignment() const { return Qt::AlignLeft | Qt::AlignVCenter; }};class GroupActionPrivate{public:	enum GroupAction {GNone, GSelect, GAdd, GEdit, GRemove};		GroupAction m_Action;	QListViewItem *m_Item;	QString m_OldName;	friend class CustomSmileyManager;};CustomSmileyManager::CustomSmileyManager()	: m_Config(0), m_IsChanged(false), m_MoveToMenu(0){	init();	connect(btnOK, SIGNAL(clicked()), this, SLOT(slotOKClicked() ));	connect(btnCancel, SIGNAL(clicked()), this, SLOT(close()));}CustomSmileyManager::~CustomSmileyManager(){	if(m_Config) delete m_Config;}void CustomSmileyManager::init( ){	// doesn't support import/export to eip package	tbtnImport->hide();	tbtnExport->hide();	// cancel does same job as ok, so hide it for now	btnCancel->hide();	lblPreview->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );	d = new GroupActionPrivate;	d->m_Action = GroupActionPrivate::GNone;	d->m_Item = 0;	d->m_OldName = "";	if(m_Config) delete m_Config;	QString dir = EvaMain::user->getSetting()->getCustomSmileyDir() + "/";	m_Config = new CustomFaceConfig(dir);	m_Config->loadXML();	// group list first	loadGroups();	// init table	initFaces();	lvGroups->setSelected( lvGroups->firstChild(), true);}void CustomSmileyManager::loadGroups( ){	if(!m_Config) return;	lvGroups->addColumn(i18n("Smiley Groups"));	lvGroups->setColumnWidth(0, lvGroups->width());	lvGroups->setItemMargin( 2 );	QStringList groups = m_Config->groupNames();	// as  QLIstView alway insert the current item on the top,	// so, just add items reversely	for( int i = (int)(groups.count() -1); i >= 0; i--){		(void) new QListViewItem(lvGroups, groups[i]);	}	connect(tbtnAddGroup, SIGNAL(clicked()), this, SLOT(slotAddGroupClicked()));	connect(tbtnEditGroup, SIGNAL(clicked()), this, SLOT(slotEditGroupClicked()));	connect(tbtnRemoveGroup, SIGNAL(clicked()), this, SLOT(slotRemoveGroupClicked()));	connect(lvGroups, SIGNAL(itemRenamed(QListViewItem*, int, const QString &)),			this, SLOT(slotGroupRenamed(QListViewItem*, int, const QString &)));	connect(lvGroups, SIGNAL(selectionChanged( QListViewItem *) ),			this, SLOT(slotGroupSelectionChanged( QListViewItem *) ) );}void CustomSmileyManager::initFaces( ){	tblFaceList->verticalHeader()->hide();	tblFaceList->horizontalHeader()->setLabel( 0, i18n("No." ) );	tblFaceList->horizontalHeader()->setLabel( 1, i18n("Smiley" ) );	tblFaceList->horizontalHeader()->setLabel( 2, i18n("Shortcut" ) );	tblFaceList->setColumnWidth(0, 15);	tblFaceList->setColumnWidth(1, tblFaceList->visibleWidth() - 15 - 60 );	tblFaceList->setLeftMargin(0);	connect(tblFaceList, SIGNAL(selectionChanged( )), this, SLOT(slotFaceSelectionChanged( )));	connect(tblFaceList, SIGNAL(valueChanged(int, int)), this, SLOT(slotFaceValueChanged(int, int)));	connect(btnAdd, SIGNAL(clicked()), this, SLOT(slotAddSmiley()));	connect(btnRemove, SIGNAL(clicked()), this, SLOT(slotRemoveSmiley()));	connect(btnEdit, SIGNAL(clicked()), this, SLOT(slotEditSmiley()));	connect(btnUp, SIGNAL(clicked()), this, SLOT(slotUpSmiley()));	connect(btnDown, SIGNAL(clicked()), this, SLOT(slotDownSmiley()));	connect(btnMoveTo, SIGNAL(clicked()), this, SLOT(slotMoveToSmiley()));}void CustomSmileyManager::loadSmileys( int groupIndex ){	// clear the table first	for(int row = 0; row < tblFaceList->numRows(); row++){			tblFaceList->removeRow(row);	}	tblFaceList->setNumRows(0);	QString dir = EvaMain::user->getSetting()->getCustomSmileyDir() + "/";	if(groupIndex>0)		dir += (m_Config->groupName( groupIndex) + "/");	FaceList list = m_Config->groupMembers( groupIndex );	int row = 0;	if(list.size()){		tblFaceList->setNumRows(list.size());		tblFaceList->horizontalHeader()->setLabel( 0, i18n("No." ) );		tblFaceList->horizontalHeader()->setLabel( 1, i18n("Smiley" ) );		tblFaceList->horizontalHeader()->setLabel( 2, i18n("Shortcut" ) );		for( FaceList::Iterator it = list.begin(); it != list.end(); ++it){			//tblFaceList->setText(row, 0, QString::number( row + 1));			tblFaceList->setItem(row, 0, 						new QTableItem(tblFaceList, QTableItem::Never,									QString::number(row + 1)));			QPixmap *pixmap = new QPixmap(dir + (*it).fixed());			CustomItem *item = new CustomItem(tblFaceList, (*it).tip(), *pixmap);			tblFaceList->setItem(row, 1, item);			CustomItem *itemSC = new CustomItem(tblFaceList, (*it).shortcut() );			tblFaceList->setItem(row, 2, itemSC);			tblFaceList->setRowHeight(row, pixmap->width() + 2);			delete pixmap;			row++;		}		tblFaceList->setColumnWidth(0, 20);		tblFaceList->setColumnWidth(1, tblFaceList->visibleWidth() - 20 - 50 );	}}void CustomSmileyManager::closeEvent( QCloseEvent * e ){	e->accept();	if(m_IsChanged){		m_Config->saveXML();		emit customSmileyChanged();	}	deleteLater();}void CustomSmileyManager::slotOKClicked( ){	if(m_IsChanged){		m_Config->saveXML();

⌨️ 快捷键说明

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