示例#1
0
文件: MapWizard.cpp 项目: KDE/marble
bool PreviewDialog::deleteTheme( const QString &directory )
{
    QDir dir(directory);
    bool result = true;
 
    if (dir.exists(directory)) {
        Q_FOREACH(const QFileInfo& info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden  | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) {
            if (info.isDir()) {
                result = deleteTheme(info.absoluteFilePath());
            } else {
                result = QFile::remove(info.absoluteFilePath());
            }
 
            if (!result) {
                return result;
            }
        }
        result = dir.rmdir(directory);
    }
示例#2
0
ThemeManager::ThemeManager(QSettings& settings, QWidget* parent)
	: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint),
	m_settings(settings)
{
	setWindowTitle(tr("Themes"));

	m_tabs = new QTabWidget(this);

	// Find view sizes
	int focush = style()->pixelMetric(QStyle::PM_FocusFrameHMargin);
	int focusv = style()->pixelMetric(QStyle::PM_FocusFrameVMargin);
	int frame = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
	int scrollbar = style()->pixelMetric(QStyle::PM_SliderThickness);
	QSize grid_size(259 + focush, 154 + focusv + (fontMetrics().height() * 2));
	QSize view_size((grid_size.width() + frame + focush) * 2 + scrollbar, (grid_size.height() + frame + focusv) * 2);

	// Add default themes tab
	QWidget* tab = new QWidget(this);
	m_tabs->addTab(tab, tr("Default"));

	// Add default themes list
	m_default_themes = new QListWidget(tab);
	m_default_themes->setSortingEnabled(true);
	m_default_themes->setViewMode(QListView::IconMode);
	m_default_themes->setIconSize(QSize(258, 153));
	m_default_themes->setGridSize(grid_size);
	m_default_themes->setMovement(QListView::Static);
	m_default_themes->setResizeMode(QListView::Adjust);
	m_default_themes->setSelectionMode(QAbstractItemView::SingleSelection);
	m_default_themes->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	m_default_themes->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
	m_default_themes->setMinimumSize(view_size);
	m_default_themes->setWordWrap(true);
	addItem("gentleblues", true, tr("Gentle Blues"));
	addItem("oldschool", true, tr("Old School"));
	addItem("spacedreams", true, tr("Space Dreams"));
	addItem("writingdesk", true, tr("Writing Desk"));

	// Add default control buttons
	QPushButton* new_default_button = new QPushButton(tr("New"), tab);
	new_default_button->setAutoDefault(false);
	connect(new_default_button, SIGNAL(clicked()), this, SLOT(newTheme()));

	m_clone_default_button = new QPushButton(tr("Duplicate"), tab);
	m_clone_default_button->setAutoDefault(false);
	connect(m_clone_default_button, SIGNAL(clicked()), this, SLOT(cloneTheme()));

	// Lay out default themes tab
	QGridLayout* default_layout = new QGridLayout(tab);
	default_layout->setColumnStretch(0, 1);
	default_layout->setRowStretch(2, 1);
	default_layout->addWidget(m_default_themes, 0, 0, 3, 1);
	default_layout->addWidget(new_default_button, 0, 1);
	default_layout->addWidget(m_clone_default_button, 1, 1);

	// Add themes tab
	tab = new QWidget(this);
	m_tabs->addTab(tab, tr("Custom"));

	// Add themes list
	m_themes = new QListWidget(tab);
	m_themes->setSortingEnabled(true);
	m_themes->setViewMode(QListView::IconMode);
	m_themes->setIconSize(QSize(258, 153));
	m_themes->setGridSize(grid_size);
	m_themes->setMovement(QListView::Static);
	m_themes->setResizeMode(QListView::Adjust);
	m_themes->setSelectionMode(QAbstractItemView::SingleSelection);
	m_themes->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	m_themes->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
	m_themes->setMinimumSize(view_size);
	m_themes->setWordWrap(true);
	QDir dir(Theme::path(), "*.theme");
	QStringList themes = dir.entryList(QDir::Files, QDir::Name | QDir::IgnoreCase);
	for (const QString& theme : themes) {
		QString name = QSettings(dir.filePath(theme), QSettings::IniFormat).value("Name").toString();
		if (!name.isEmpty()) {
			addItem(QFileInfo(theme).completeBaseName(), false, name);
		} else {
			name = QUrl::fromPercentEncoding(QFileInfo(theme).completeBaseName().toUtf8());
			QSettings(dir.filePath(theme), QSettings::IniFormat).setValue("Name", name);

			QString id = Theme::createId();
			dir.rename(theme, id + ".theme");
			dir.remove(QFileInfo(theme).completeBaseName() + ".png");

			QStringList sessions = QDir(Session::path(), "*.session").entryList(QDir::Files);
			sessions.prepend("");
			for (const QString& file : sessions) {
				Session session(file);
				if ((session.theme() == name) && (session.themeDefault() == false)) {
					session.setTheme(id, false);
				}
			}

			addItem(id, false, name);
		}
	}

	// Add control buttons
	QPushButton* new_button = new QPushButton(tr("New"), tab);
	new_button->setAutoDefault(false);
	connect(new_button, SIGNAL(clicked()), this, SLOT(newTheme()));

	m_clone_button = new QPushButton(tr("Duplicate"), tab);
	m_clone_button->setAutoDefault(false);
	m_clone_button->setEnabled(false);
	connect(m_clone_button, SIGNAL(clicked()), this, SLOT(cloneTheme()));

	m_edit_button = new QPushButton(tr("Edit"), tab);
	m_edit_button->setAutoDefault(false);
	m_edit_button->setEnabled(false);
	connect(m_edit_button, SIGNAL(clicked()), this, SLOT(editTheme()));

	m_remove_button = new QPushButton(tr("Delete"), tab);
	m_remove_button->setAutoDefault(false);
	m_remove_button->setEnabled(false);
	connect(m_remove_button, SIGNAL(clicked()), this, SLOT(deleteTheme()));

	QPushButton* import_button = new QPushButton(tr("Import"), tab);
	import_button->setAutoDefault(false);
	connect(import_button, SIGNAL(clicked()), this, SLOT(importTheme()));

	m_export_button = new QPushButton(tr("Export"), tab);
	m_export_button->setAutoDefault(false);
	m_export_button->setEnabled(false);
	connect(m_export_button, SIGNAL(clicked()), this, SLOT(exportTheme()));

	// Lay out custom themes tab
	QGridLayout* custom_layout = new QGridLayout(tab);
	custom_layout->setColumnStretch(0, 1);
	custom_layout->setRowMinimumHeight(4, import_button->sizeHint().height());
	custom_layout->setRowStretch(7, 1);
	custom_layout->addWidget(m_themes, 0, 0, 8, 1);
	custom_layout->addWidget(new_button, 0, 1);
	custom_layout->addWidget(m_clone_button, 1, 1);
	custom_layout->addWidget(m_edit_button, 2, 1);
	custom_layout->addWidget(m_remove_button, 3, 1);
	custom_layout->addWidget(import_button, 5, 1);
	custom_layout->addWidget(m_export_button, 6, 1);

	// Lay out dialog
	QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, this);
	connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));

	QVBoxLayout* layout = new QVBoxLayout(this);
	layout->addWidget(m_tabs, 1);
	layout->addSpacing(layout->margin());
	layout->addWidget(buttons);

	// Select theme
	QString theme = m_settings.value("ThemeManager/Theme").toString();
	bool is_default = m_settings.value("ThemeManager/ThemeDefault", false).toBool();
	if (!selectItem(theme, is_default)) {
		selectItem(Theme::defaultId(), true);
	}
	selectionChanged(is_default);
	connect(m_default_themes, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(currentThemeChanged(QListWidgetItem*)));
	connect(m_themes, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(currentThemeChanged(QListWidgetItem*)));
	connect(m_themes, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(editTheme()));

	// Restore size
	resize(m_settings.value("ThemeManager/Size", sizeHint()).toSize());
}
示例#3
0
void MyServer::slotReadClient()
{

    QTcpSocket* pClientSocket = (QTcpSocket*)sender();

    QDataStream in(pClientSocket);
    in.setVersion(QDataStream::Qt_5_3);


    for(;;){

        if(!nextBlockSize){
            if(pClientSocket->bytesAvailable() < sizeof(quint32)) {
                break;
            }

            in >> nextBlockSize;
        }

        if(pClientSocket->bytesAvailable() < nextBlockSize) {
            break;
        }


        QString request;
        in >> request;

        QStringList req_param = request.split(" ");

        if(req_param.at(0) == "GETCURRENTVERSION")
            sendCurrVers(pClientSocket);

        if(req_param.at(0) == "GETSUBJECTS")
            sendArrayToClient(pClientSocket,getSubjects());

        if(req_param.at(0) == "GETTHEMES")
            sendArrayToClient(pClientSocket,getThemes(req_param.at(1)));

        if(req_param.at(0) == "GETPICTURES")
            sendArrayToClient(pClientSocket,getPictures(req_param.at(1),req_param.at(2)));

        if(req_param.at(0) == "GETIMAGE")
            sendImageToClient(pClientSocket,getImage(req_param.at(1)));

        if(req_param.at(0) == "PUTSUBJECT"){
            putSubject(req_param.at(1));
            version++;
        }
        if(req_param.at(0) == "PUTTHEME"){
            putTheme(req_param.at(1),req_param.at(2));
            version++;
        }
        if(req_param.at(0) == "PUTIMAGE")
        {
            QImage img;

            in >> img;

            quint32 k = putImage(img,req_param.at(1),req_param.at(2), req_param.at(3));
            version++;
            QList<QString> lst;
            lst << QString("%1").arg(k);
            sendArrayToClient(pClientSocket,lst);
        }
        if(req_param.at(0) == "DELETESUBJECT"){
            deleteSubject(req_param.at(1));
            version++;
        }
        if(req_param.at(0) == "DELETETHEME"){
            deleteTheme(req_param.at(1),req_param.at(2));
            version++;
        }
        if(req_param.at(0) == "DELETEIMAGE"){
            deleteImage(req_param.at(1));
            version++;
        }
        if(req_param.at(0) == "SWAPIMAGE"){
            QImage img;

            in >> img;

            swapImage(img,req_param.at(1));
            version++;
        }
示例#4
0
PreferencesDialog::PreferencesDialog(QWidget * parent, Qt::WindowFlags f)
    : QDialog(parent, f), ui(new Ui::PreferencesDialogBox())
{
    ui->setupUi(this);

    NewEmptyMapDialog dialog;
    ui->m_defaultMapModeCombo->addItems(dialog.getPermissionData());

    m_preferences = PreferencesManager::getInstance();

    m_aliasModel = new DiceAliasModel();
    ui->m_tableViewAlias->setModel(m_aliasModel);
    m_diceParser = new DiceParser();
    m_aliasModel->setAliases(m_diceParser->getAliases());

    QHeaderView* horizontalHeader = ui->m_tableViewAlias->horizontalHeader();
    horizontalHeader->setSectionResizeMode(DiceAliasModel::PATTERN,QHeaderView::ResizeToContents);
    horizontalHeader->setSectionResizeMode(DiceAliasModel::VALUE,QHeaderView::Stretch);
    horizontalHeader->setSectionResizeMode(DiceAliasModel::METHOD,QHeaderView::ResizeToContents);
    ui->m_tableViewAlias->setItemDelegateForColumn(DiceAliasModel::METHOD,new CheckBoxDelegate());

    m_paletteModel = new PaletteModel();
    m_paletteModel->setPalette(palette());
    ui->m_paletteTableView->setModel(m_paletteModel);
    horizontalHeader = ui->m_paletteTableView->horizontalHeader();
    horizontalHeader->setSectionResizeMode(0,QHeaderView::Stretch);

    connect(this, SIGNAL(accepted()), this, SLOT(save()));

    connect(ui->m_startDiag,SIGNAL(clicked()),this,SLOT(performDiag()));
    //ui->m_fogColor->setTransparency(true);

    //set general panel as default.
    ui->tabWidget->setCurrentIndex(0);

    //aliases
    connect(ui->m_addDiceAliasAct,SIGNAL(clicked()),this,SLOT(managedAction()));
    connect(ui->m_delDiceAliasAct,SIGNAL(clicked()),this,SLOT(managedAction()));
    connect(ui->m_upDiceAliasAct,SIGNAL(clicked()),this,SLOT(managedAction()));
    connect(ui->m_downDiceAliasAct,SIGNAL(clicked()),this,SLOT(managedAction()));
    connect(ui->m_topDiceAliasAct,SIGNAL(clicked()),this,SLOT(managedAction()));
    connect(ui->m_bottomDiceAliasAct,SIGNAL(clicked()),this,SLOT(managedAction()));
    connect(ui->m_testPushButton,SIGNAL(clicked()),this,SLOT(testAliasCommand()));

    // Misc
    setSizeGripEnabled(true);
    setWindowTitle(QString("%1 - %2").arg(m_preferences->value("Application_Name","rolisteam").toString(),tr("Preferences")));
    setWindowModality(Qt::ApplicationModal);


    m_preferences->registerListener("isPlayer",m_aliasModel);
    m_aliasModel->setGM(!m_preferences->value("isPlayer",false).toBool());


    // background
    connect(ui->m_positioningComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(applyBackground()));
    connect(ui->m_bgColorPush, SIGNAL(colorChanged(QColor)), this, SLOT(applyBackground()));
    connect(ui->m_backgroundImage,SIGNAL(pathChanged()),this,SLOT(applyBackground()));

    //themes
    connect(ui->m_copyThemeButton,SIGNAL(clicked()),this,SLOT(dupplicateTheme()));
    connect(ui->m_themeNameLineEdit,SIGNAL(textEdited(QString)),this,SLOT(setTitleAtCurrentTheme()));


    connect(ui->m_paletteTableView,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(editColor(QModelIndex)));
    connect(ui->m_cssEdit,SIGNAL(clicked()),this,SLOT(editCss()));
    connect(ui->m_exportBtn,SIGNAL(clicked()),this,SLOT(exportTheme()));
    connect(ui->m_importBtn,SIGNAL(clicked()),this,SLOT(importTheme()));
    connect(ui->m_deleteTheme,SIGNAL(clicked()),this,SLOT(deleteTheme()));

}
示例#5
0
void ThemeManagementDialog::contextMenuRequested(const QPoint & pos)
{
	ThemeListWidgetItem * pItem = dynamic_cast<ThemeListWidgetItem *>(m_pListWidget->itemAt(pos));
	if(pItem != 0)
	{
		m_pListWidget->setCurrentItem(pItem);
		m_pContextPopup->clear();

		KviThemeInfo * pInfo = pItem->themeInfo();
		if(!pInfo)
			return;

		if(!pInfo->isBuiltin())
			m_pContextPopup->addAction(*(g_pIconManager->getSmallIcon(KviIconManager::Minus)),__tr2qs_ctx("&Remove Theme","theme"),this,SLOT(deleteTheme()));

		m_pContextPopup->addAction(*(g_pIconManager->getSmallIcon(KviIconManager::Accept)),__tr2qs_ctx("&Apply Theme","theme"),this,SLOT(applyCurrentTheme()));
		m_pContextPopup->popup(m_pListWidget->viewport()->mapToGlobal(pos));
	}
}
示例#6
0
ThemeManagementDialog::ThemeManagementDialog(QWidget * parent)
: QWidget(parent)
{
	m_pItemDelegate = NULL;
#ifdef COMPILE_WEBKIT_SUPPORT
	m_pWebThemeInterfaceDialog = NULL;
#endif
	setObjectName("theme_options_widget");
	setWindowTitle(__tr2qs_ctx("Manage Themes - KVIrc","theme"));
	setWindowIcon(*(g_pIconManager->getSmallIcon(KviIconManager::Theme)));

	m_pInstance = this;

	//QGridLayout * g = new QGridLayout(this);
	QVBoxLayout * pVBox = new QVBoxLayout(this);
	KviTalHBox * pHBox = new KviTalHBox(this);
	pHBox->setMargin(1);
	pHBox->setSpacing(1);
	//g->addWidget(pHBox,0,0);
	pVBox->addWidget(pHBox);
	QToolButton * pTool;
	QFrame * pSep;

	pTool = new QToolButton(pHBox);
	pTool->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_SAVE)));
	pTool->setIconSize(QSize(32,32));
	pTool->setToolTip(__tr2qs_ctx("Save Current Theme...","theme"));
	connect(pTool,SIGNAL(clicked()),this,SLOT(saveCurrentTheme()));

	pSep = new QFrame(pHBox);
	pSep->setFrameStyle(QFrame::VLine | QFrame::Sunken);
	pSep->setMinimumWidth(12);

	m_pPackThemeButton = new QToolButton(pHBox);
	m_pPackThemeButton->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_PACK)));

	m_pPackThemeButton->setIconSize(QSize(32,32));
	m_pPackThemeButton->setToolTip(__tr2qs_ctx("Export Selected Themes to a Distributable Package","theme"));
	connect(m_pPackThemeButton,SIGNAL(clicked()),this,SLOT(packTheme()));

	m_pDeleteThemeButton = new QToolButton(pHBox);
	m_pDeleteThemeButton->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_REMOVE)));
	m_pDeleteThemeButton->setIconSize(QSize(32,32));
	m_pDeleteThemeButton->setToolTip(__tr2qs_ctx("Delete Selected Themes","theme"));
	connect(m_pDeleteThemeButton,SIGNAL(clicked()),this,SLOT(deleteTheme()));

	pSep = new QFrame(pHBox);
	pSep->setFrameStyle(QFrame::VLine | QFrame::Sunken);
	pSep->setMinimumWidth(12);

	pTool = new QToolButton(pHBox);
	pTool->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_OPEN)));
	pTool->setIconSize(QSize(32,32));
	pTool->setToolTip(__tr2qs_ctx("Install Theme Package From Disk","theme"));
	connect(pTool,SIGNAL(clicked()),this,SLOT(installFromFile()));

	pTool = new QToolButton(pHBox);
	pTool->setIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_WWW)));
	pTool->setIconSize(QSize(32,32));
	pTool->setToolTip(__tr2qs_ctx("Get More Themes...","theme"));
	connect(pTool,SIGNAL(clicked()),this,SLOT(getMoreThemes()));

	QWidget *w= new QWidget(pHBox);
	w->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum);

	m_pListWidget = new KviTalListWidget(this);
	m_pListWidget->setContextMenuPolicy(Qt::CustomContextMenu);
	m_pItemDelegate = new KviTalIconAndRichTextItemDelegate(m_pListWidget);
	m_pItemDelegate->setDefaultIcon(g_pIconManager->getBigIcon(QString(KVI_BIGICON_THEME)));
	m_pListWidget->setItemDelegate(m_pItemDelegate);
	m_pListWidget->setMinimumHeight(400);
	m_pListWidget->setMinimumWidth(420);

	m_pListWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
	m_pListWidget->setSortingEnabled(true);
	connect(m_pListWidget,SIGNAL(itemDoubleClicked(QListWidgetItem *)),this,SLOT(applyTheme(QListWidgetItem *)));


	//FIXME tooltip
	//connect(m_pListWidget,SIGNAL(tipRequest(QListWidgetItem *,const QPoint &)),this,SLOT(tipRequest(QListWidgetItem *,const QPoint &)));
	connect(m_pListWidget,SIGNAL(customContextMenuRequested(const QPoint &)),
		this,SLOT(contextMenuRequested(const QPoint &)));
	connect(m_pListWidget,SIGNAL(itemSelectionChanged()),this,SLOT(enableDisableButtons()));

	pSep = new QFrame(this);
	pSep->setFrameStyle(QFrame::HLine | QFrame::Sunken);
	pSep->setMinimumWidth(300);
	pSep->setMinimumHeight(8);
	pVBox->addWidget(pSep);

	//g->addWidget(pSep,2,0);

	m_pCurrentInstalledThemeLabel = new QLabel(this);
	m_pCurrentInstalledThemeLabel->setText(__tr2qs_ctx("<b><u>Current Installed Theme:</u> ","theme") + " " + KVI_OPTION_STRING(KviOption_stringIconThemeSubdir) + "</b>");
//	g->addWidget(pLabel,2,0);
	pVBox->addWidget(m_pCurrentInstalledThemeLabel);

	pSep = new QFrame(this);
	pSep->setFrameStyle(QFrame::HLine | QFrame::Sunken);
	pSep->setMinimumWidth(300);

//	g->addWidget(pSep,3,0);
	pVBox->addWidget(pSep);

//	g->addWidget(m_pListWidget,4,0);
	pVBox->addWidget(m_pListWidget);

//	KviDynamicToolTip * tip = new KviDynamicToolTip(m_pListWidget);
//	connect(tip,SIGNAL(tipRequest(KviDynamicToolTip *,const QPoint &)),this,SLOT(tipRequest(KviDynamicToolTip *,const QPoint &)));

	QPushButton * b = new QPushButton(__tr2qs("Close"),this);
	b->setMaximumSize(b->sizeHint().width(),b->sizeHint().height());
	connect(b,SIGNAL(clicked()),this,SLOT(closeClicked()));
//	g->addWidget(b,5,0);
	pVBox->addWidget(b);

//	g->setMargin(1);
//	g->setSpacing(1);
	pVBox->setAlignment(b,Qt::AlignRight);
	fillThemeBox();
	m_pContextPopup = new QMenu(this);

	if(g_rectManagementDialogGeometry.y() < 5)
	{
		g_rectManagementDialogGeometry.setY(5);
	}
	resize(g_rectManagementDialogGeometry.width(),
		g_rectManagementDialogGeometry.height());

	QRect rect = g_pApp->desktop()->screenGeometry(g_pMainWindow);
	move(rect.x() + ((rect.width() - g_rectManagementDialogGeometry.width())/2),rect.y() + ((rect.height() - g_rectManagementDialogGeometry.height())/2));

	new QShortcut(Qt::Key_Escape, this, SLOT(closeClicked()));
}