Merge pull request #1102 from openscad/text-fixes-part6

Text fixes (part 6)
master
Marius Kintel 2014-12-23 00:03:34 -05:00
commit 756d3e2a97
11 changed files with 196 additions and 23 deletions

View File

@ -259,6 +259,7 @@ HEADERS += src/typedefs.h \
src/OpenCSGWarningDialog.h \
src/AboutDialog.h \
src/FontListDialog.h \
src/FontListTableView.h \
src/builtin.h \
src/calc.h \
src/context.h \
@ -428,6 +429,7 @@ SOURCES += src/version_check.cc \
src/UIUtils.cc \
src/Dock.cc \
src/FontListDialog.cc \
src/FontListTableView.cc \
src/launchingscreen.cc \
src/legacyeditor.cc \
src/LibraryInfoDialog.cc

View File

@ -60,14 +60,16 @@ void FontListDialog::selection_changed(const QItemSelection &current, const QIte
{
if (current.count() == 0) {
copyButton->setEnabled(false);
tableView->setDragText("");
return;
}
const QModelIndex &idx = proxy->mapToSource(current.indexes().at(0));
const QString name = model->item(idx.row(), 0)->text();
const QString style = model->item(idx.row(), 1)->text();
selection = QString("\"%1:style=%2\"").arg(name).arg(style);
selection = QString("\"%1:style=%2\"").arg(quote(name)).arg(quote(style));
copyButton->setEnabled(true);
tableView->setDragText(selection);
}
void FontListDialog::update_font_list()
@ -117,3 +119,28 @@ void FontListDialog::update_font_list()
delete list;
}
/**
* Quote a string according to the requirements of font-config.
* See http://www.freedesktop.org/software/fontconfig/fontconfig-user.html
*
* The '\', '-', ':' and ',' characters in family names must be preceded
* by a '\' character to avoid having them misinterpreted. Similarly, values
* containing '\', '=', '_', ':' and ',' must also have them preceded by a
* '\' character. The '\' characters are stripped out of the family name and
* values as the font name is read.
*
* @param text unquoted string
* @return quoted text
*/
QString FontListDialog::quote(const QString& text)
{
QString result = text;
result.replace('\\', "\\\\")
.replace('-', "\\-")
.replace(':', "\\:")
.replace(',', "\\,")
.replace('=', "\\=")
.replace('_', "\\_");
return result;
}

View File

@ -6,9 +6,6 @@
#include "qtgettext.h"
#include "ui_FontListDialog.h"
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
class FontListDialog : public QDialog, public Ui::FontListDialog
{
Q_OBJECT;
@ -27,6 +24,8 @@ signals:
void font_selected(const QString font);
private:
QString quote(const QString& text);
QString selection;
QStandardItemModel *model;
QSortFilterProxyModel *proxy;

View File

@ -67,7 +67,17 @@
</widget>
</item>
<item row="2" column="0" colspan="5">
<widget class="QTableView" name="tableView"/>
<widget class="FontListTableView" name="tableView">
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragOnly</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
<item row="0" column="0" colspan="5">
<widget class="QLabel" name="label">
@ -100,6 +110,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>FontListTableView</class>
<extends>QTableView</extends>
<header>FontListTableView.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../openscad.qrc"/>
</resources>

66
src/FontListTableView.cc Normal file
View File

@ -0,0 +1,66 @@
/*
* OpenSCAD (www.openscad.org)
* Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and
* Marius Kintel <marius@kintel.net>
*
* 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.
*
* As a special exception, you have permission to link this program
* with the CGAL library and distribute executables, as long as you
* follow the requirements of the GNU GPL in regard to all of the
* software in the executable aside from CGAL.
*
* 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 <QDrag>
#include <QPixmap>
#include <QPainter>
#include <QMimeData>
#include "qtgettext.h"
#include "FontListDialog.h"
FontListTableView::FontListTableView(QWidget *parent) : QTableView(parent)
{
}
void FontListTableView::setDragText(const QString &text)
{
this->text = text.trimmed();
}
void FontListTableView::startDrag(Qt::DropActions supportedActions)
{
if (text.isEmpty()) {
return;
}
QMimeData *mimeData = new QMimeData;
mimeData->setText(text);
QFontMetrics fm(font());
QRect rect(0, 0, fm.width(text), fm.height());
QPixmap pixmap(rect.width(), rect.height());
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
painter.setFont(font());
painter.drawText(rect, Qt::AlignCenter, text);
QDrag *drag = new QDrag(this);
drag->setPixmap(pixmap);
drag->setMimeData(mimeData);
drag->setHotSpot(QPoint(-10, rect.height() + 6));
drag->exec(supportedActions, Qt::CopyAction);
}

18
src/FontListTableView.h Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include <QTableView>
class FontListTableView : public QTableView
{
Q_OBJECT;
public:
FontListTableView(QWidget *parent = NULL);
void setDragText(const QString &text);
protected:
void startDrag(Qt::DropActions supportedActions);
private:
QString text;
};

View File

@ -2,6 +2,7 @@
#include <QSettings>
#include <QListWidgetItem>
#include "openscad.h"
#include "launchingscreen.h"
#include "ui_launchingscreen.h"
@ -26,7 +27,9 @@ LaunchingScreen::LaunchingScreen(QWidget *parent) : QDialog(parent)
setupUi(this);
this->setStyleSheet("QDialog {background-image:url(':/icons/background.png')}"
"QPushButton {color:white;}");
this->versionNumberLabel->setText(openscad_version.c_str());
QStringList recentFiles = UIUtils::recentFiles();
for (int a = 0;a < recentFiles.size();a++) {
QFileInfo fileInfo(recentFiles[a]);
@ -75,7 +78,7 @@ QString LaunchingScreen::selectedFile()
return this->selection;
}
void LaunchingScreen::enableRecentButton(const QModelIndex & current, const QModelIndex & previous)
void LaunchingScreen::enableRecentButton(const QModelIndex &, const QModelIndex &)
{
this->openRecentButton->setEnabled(true);
this->openRecentButton->setDefault(true);
@ -91,7 +94,7 @@ void LaunchingScreen::openRecent()
checkOpen(item->data(Qt::UserRole));
}
void LaunchingScreen::enableExampleButton(QTreeWidgetItem *current, QTreeWidgetItem *previous)
void LaunchingScreen::enableExampleButton(QTreeWidgetItem *current, QTreeWidgetItem *)
{
const bool enable = current->childCount() == 0;
this->openExampleButton->setEnabled(enable);

View File

@ -6,10 +6,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>618</width>
<width>620</width>
<height>418</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>600</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Welcome to OpenSCAD</string>
</property>
@ -331,16 +337,32 @@ QPushButton:pressed {
</item>
</layout>
</item>
<item row="8" column="0" colspan="2">
<item row="8" column="1">
<widget class="QLabel" name="versionNumberLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Version</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QCheckBox" name="checkBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>600</width>
<height>0</height>
</size>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="autoFillBackground">
<bool>false</bool>

View File

@ -24,6 +24,7 @@
*
*/
#include <iostream>
#include "openscad.h"
#include "GeometryCache.h"
#include "ModuleCache.h"
#include "MainWindow.h"
@ -124,15 +125,8 @@ QSet<MainWindow*> *MainWindow::getWindows()
// Global application state
unsigned int GuiLocker::gui_locked = 0;
#define QUOTE(x__) # x__
#define QUOTED(x__) QUOTE(x__)
static std::string helptitle = openscad_version + "\nhttp://www.openscad.org\n\n";
static char helptitle[] =
"OpenSCAD " QUOTED(OPENSCAD_VERSION)
#ifdef OPENSCAD_COMMIT
" (git " QUOTED(OPENSCAD_COMMIT) ")"
#endif
"\nhttp://www.openscad.org\n\n";
static char copyrighttext[] =
"Copyright (C) 2009-2014 The OpenSCAD Developers\n"
"\n"
@ -189,6 +183,9 @@ MainWindow::MainWindow(const QString &filename)
this->consoleDock->setConfigKey("view/hideConsole");
this->consoleDock->setAction(this->viewActionHideConsole);
QLabel *versionLabel = new QLabel(openscad_version.c_str());
this->statusbar->addPermanentWidget(versionLabel);
QSettings settings;
editortype = settings.value("editor/editortype").toString();
useScintilla = (editortype != "Simple Editor");

View File

@ -90,6 +90,17 @@ std::string currentdir;
static bool arg_info = false;
static std::string arg_colorscheme;
#define QUOTE(x__) # x__
#define QUOTED(x__) QUOTE(x__)
std::string openscad_versionnumber = QUOTED(OPENSCAD_VERSION)
#ifdef OPENSCAD_COMMIT
" (git " QUOTED(OPENSCAD_COMMIT) ")"
#endif
;
std::string openscad_version = "OpenSCAD " + openscad_versionnumber;
class Echostream : public std::ofstream
{
public:
@ -616,6 +627,9 @@ int gui(vector<string> &inputFiles, const fs::path &original_path, int argc, cha
}
#endif
QApplication app(argc, argv, true); //useGUI);
// remove ugly frames in the QStatusBar when using additional widgets
app.setStyleSheet("QStatusBar::item { border: 0px solid black }; ");
#ifdef Q_OS_MAC
app.installEventFilter(new EventFilter(&app));
#endif

View File

@ -34,3 +34,11 @@ extern std::string commandline_commands;
// The CWD when application started. We shouldn't change CWD, but until we stop
// doing this, use currentdir to get the original CWD.
extern std::string currentdir;
extern std::string versionnumber;
// Just the number (might have the git commit as suffix), e.g. 2014.12.23.
extern std::string openscad_versionnumber;
// The string "OpenSCAD " and the version number.
extern std::string openscad_version;