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

📄 preview.cpp

📁 四川麻将程序代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include <iostream.h>#include <sys/param.h> #include <kapp.h>#include <qdir.h>#include <qpixmap.h>#include <qimage.h>#include <qregexp.h>#include <kfiledialog.h>#include <qpainter.h>#include <qfile.h>#include "Preview.h"#include "Preview.moc"#include "Preferences.h"#include "kmessagebox.h"#include "kstddirs.h"#include "kglobal.h"#include "klocale.h"#include <qfileinfo.h>#include <qpushbt.h>#include <qcombobox.h>#include <qbttngrp.h>                       static const char * themeMagicV1_0= "kmahjongg-theme-v1.0";Preview::Preview(	QWidget* parent,	const char* name)	:	QDialog( parent, name, TRUE, 0 ), tiles(true){	const int dx=0;	const int dy = 66;	bottomGroup = new QButtonGroup( this, "bottomGroup" );	bottomGroup->setGeometry( 10, 230+dy, 310+dx, 50 );	bottomGroup->setMinimumSize( 0, 0 );	bottomGroup->setMaximumSize( 32767, 32767 );	bottomGroup->setFocusPolicy( QWidget::NoFocus );	bottomGroup->setBackgroundMode( QWidget::PaletteBackground );	bottomGroup->setFontPropagation( QWidget::NoChildren );	bottomGroup->setPalettePropagation( QWidget::NoChildren );	bottomGroup->setFrameStyle( 49 );	bottomGroup->setTitle( "" );	bottomGroup->setAlignment( 1 );	topGroup = new QButtonGroup( this, "topGroup" );	topGroup->setGeometry( 10, 10, 310+dx, 50);	topGroup->setMinimumSize( 0, 0 );	topGroup->setMaximumSize( 32767, 32767 );	topGroup->setFocusPolicy( QWidget::NoFocus );	topGroup->setBackgroundMode( QWidget::PaletteBackground );	topGroup->setFontPropagation( QWidget::NoChildren );	topGroup->setPalettePropagation( QWidget::NoChildren );	topGroup->setFrameStyle( 49 );	topGroup->setTitle( "" );	topGroup->setAlignment( 1 );	combo = new QComboBox( FALSE, this, "combo" );	combo->setGeometry( 20, 20, 220+dx, 25 );	combo->setMinimumSize( 0, 0 );	combo->setMaximumSize( 32767, 32767 );	combo->setFocusPolicy( QWidget::StrongFocus );	combo->setBackgroundMode( QWidget::PaletteBackground );	combo->setFontPropagation( QWidget::AllChildren );	combo->setPalettePropagation( QWidget::AllChildren );	combo->setSizeLimit( 10 );	combo->setAutoResize( FALSE );	connect( combo, SIGNAL(activated(int)), SLOT(selectionChanged(int)) );	loadButton = new QPushButton( this, "loadButton" );	loadButton->setGeometry( 250+dx, 20, 61, 26 );	loadButton->setMinimumSize( 0, 0 );	loadButton->setMaximumSize( 32767, 32767 );	connect( loadButton, SIGNAL(clicked()), SLOT(load()) );	loadButton->setFocusPolicy( QWidget::TabFocus );	loadButton->setBackgroundMode( QWidget::PaletteBackground );	loadButton->setFontPropagation( QWidget::NoChildren );	loadButton->setPalettePropagation( QWidget::NoChildren );	loadButton->setText(i18n("Load"));	loadButton->setAutoRepeat( FALSE );	loadButton->setAutoResize( FALSE );	//       total w  - button tot wid /4 (space left)	int bw = ((310+dx) - ((90+(dx/3))*3))/4 ;	int pos = bw +10;		okButton = new QPushButton( this, "okButton" );	okButton->setGeometry( pos, 240+dy, 90+(dx/3), 26 ); // was 20	okButton->setMinimumSize( 0, 0 );	okButton->setMaximumSize( 32767, 32767 );	connect( okButton, SIGNAL(clicked()), SLOT(ok()) );	okButton->setFocusPolicy( QWidget::TabFocus );	okButton->setBackgroundMode( QWidget::PaletteBackground );	okButton->setFontPropagation( QWidget::NoChildren );	okButton->setPalettePropagation( QWidget::NoChildren );	okButton->setText( i18n("&OK") );	okButton->setAutoRepeat( FALSE );        okButton->setAutoResize( FALSE );        okButton->setDefault(true);	pos += (90+(dx/3))+bw;	applyButton = new QPushButton( this, "applyButton" );	applyButton->setGeometry( pos, 240+dy, 90+(dx/3), 26 );	applyButton->setMinimumSize( 0, 0 );	applyButton->setMaximumSize( 32767, 32767 );	connect( applyButton, SIGNAL(clicked()), SLOT(apply()) );	applyButton->setFocusPolicy( QWidget::TabFocus );	applyButton->setBackgroundMode( QWidget::PaletteBackground );	applyButton->setFontPropagation( QWidget::NoChildren );	applyButton->setPalettePropagation( QWidget::NoChildren );	applyButton->setText( i18n("Apply") );	applyButton->setAutoRepeat( FALSE );	applyButton->setAutoResize( FALSE );	pos += (90+(dx/3))+bw;	cancelButton = new QPushButton( this, "cancelButton" );	cancelButton->setGeometry( pos, 240+dy, 90+(dx/3), 26 );	cancelButton->setMinimumSize( 0, 0 );	cancelButton->setMaximumSize( 32767, 32767 );	connect( cancelButton, SIGNAL(clicked()), SLOT(reject()) );	cancelButton->setFocusPolicy( QWidget::TabFocus );	cancelButton->setBackgroundMode( QWidget::PaletteBackground );	cancelButton->setFontPropagation( QWidget::NoChildren );	cancelButton->setPalettePropagation( QWidget::NoChildren );	cancelButton->setText( i18n("&Cancel") );	cancelButton->setAutoRepeat( FALSE );	cancelButton->setAutoResize( FALSE );	drawFrame = new FrameImage( this, "drawFrame" );	drawFrame->setGeometry( 10, 60, 310+dx, 170+dy );	drawFrame->setMinimumSize( 0, 0 );	drawFrame->setMaximumSize( 32767, 32767 );	drawFrame->setFocusPolicy( QWidget::NoFocus );	drawFrame->setBackgroundMode( QWidget::PaletteBackground );	drawFrame->setFontPropagation( QWidget::NoChildren );	drawFrame->setPalettePropagation( QWidget::NoChildren );	drawFrame->setFrameStyle( 49 );	bottomGroup->insert( okButton );	bottomGroup->insert( applyButton );	bottomGroup->insert( cancelButton );	topGroup->insert( loadButton );	resize( 330+dx, 290+dy );	setMinimumSize( 330+dx, 290+dy );	setMaximumSize( 330+dx, 290+dy );	changed = false;}Preview::~Preview(){}void Preview::selectionChanged(int which) {	QFileInfo *f= fileList.at(which);	selectedFile = f->filePath();	drawPreview();	drawFrame->repaint(0,0,-1,-1,false);	markChanged();}bool Preview::isChanged(void) {	return changed;}void Preview::markChanged(void){	changed = true;}void Preview::markUnchanged(void){	changed = false;}void Preview::initialise(const PreviewType type, const char *extension){	// set up the concept of the current file. Initialised to the preferences	// value initially. Set the caption to indicate what we are doing	switch (type) {	    case background:		      setCaption(kapp->makeStdCaption(i18n("Change background image")));		      selectedFile = preferences.background();		      fileSelector = i18n("*.bgnd|Background Image\n"				     "*.bmp|Windows bitmap file (*.bmp)\n");		  break;            case tileset:		      setCaption(kapp->makeStdCaption(i18n("Change tile set")));		      fileSelector = i18n("*.tileset|Tile set file\n");		      selectedFile = preferences.tileset();		  break;            case board:		      fileSelector = i18n("*.layout|Board layout file\n");		      setCaption(kapp->makeStdCaption(i18n("Change board layout")));		      selectedFile = preferences.layout();	          break;	    case theme:		     fileSelector = i18n("*.theme|Kmahjongg theme\n");		     setCaption(kapp->makeStdCaption(i18n("Choose a theme")));		     selectedFile="";		     themeLayout="";		     themeBack="";		     themeTileset="";            default:                  break;	}	fileSelector += i18n("*.*|All files\n");	applyButton->setEnabled(type != board);	previewType = type;	// we start with no change indicated	markUnchanged();	QString kmDir;	QDir files;	QFileInfo *current=new QFileInfo(selectedFile);	bool oneFound = false;	// we pick up system files from the kde dir	kmDir = locate("appdata", "pics/default.tileset");	QFileInfo f(kmDir);	kmDir = f.dirPath();	files.cd(kmDir);	files.setNameFilter(extension);	files.setFilter(QDir::Files | QDir::Readable);	// get rid of files from the last invocation	fileList.clear();	// deep copy the file list as we need to keen to keep it	QFileInfoList *list = (QFileInfoList *) files.entryInfoList(); 	// put the curent entry in the returned list to test for	// duplicates on insertion	list->insert(0, current);	QFileInfo *info=list->first();	for (unsigned int p=0; p<list->count(); p++) {		if (fileList.find(info) == -1) {		fileList.append( new QFileInfo(*info));		}		info=list->next();	}		// copy the file basenames into the combo box	combo->clear();	if (fileList.count() >0) {		QFileInfo *cur=fileList.first();		for (unsigned int each=0; each < fileList.count(); each++) {			combo->insertItem(cur->baseName());			cur = fileList.next();		}		oneFound = true;		}	combo->setEnabled(oneFound);	drawPreview();	}void Preview::apply(void) {	if (isChanged()) {		applyChange();		markUnchanged();		}}void Preview::ok(void) {	apply();	accept();}void Preview::load(void) {    KURL url = KFileDialog::getOpenURL(                                 NULL,				fileSelector,                                this,                                i18n("Open board layout." ));      if (  !url.isEmpty() ) {        selectedFile = url.path();         drawPreview();        drawFrame->repaint(0,0,-1,-1,false);        markChanged();     }}// Top level preview drawing method. Background, tileset and layout// are initialised from the preferences. Depending on the type// of preview dialog we pick up the selected file for one of these// chaps.void Preview::drawPreview(void) {    QString back = preferences.background();    QString tile = preferences.tileset();    QString layout = preferences.layout();    switch (previewType) {	case background:		back = selectedFile;	     break;        case tileset:		tile = selectedFile;             break;        case board:		layout = selectedFile;	     break;		case theme:	     // a theme is quite a bit of work. We load the	     // specified bits in (layout, background and tileset		    if (selectedFile != "") {		char backRaw[MAXPATHLEN];		char layoutRaw[MAXPATHLEN];		char tilesetRaw[MAXPATHLEN];		char magic[MAXPATHLEN];

⌨️ 快捷键说明

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