Add font and color preferences. Unfortunately Qt doesn't have a color

picker widget so we're back to popping up dialogs. Move the contents of
monospace_font.{cpp,h} to wireshark_application.{cpp,h}.

Pango and Qt use completely different string representations for fonts.
Add a separate gui.qt.font_name preference so that they don't clobber
each other.

svn path=/trunk/; revision=47240
This commit is contained in:
Gerald Combs 2013-01-24 01:10:12 +00:00
parent 70755ffa17
commit 2dff8d7605
22 changed files with 697 additions and 337 deletions

View File

@ -1915,7 +1915,10 @@ prefs_register_modules(void)
prefs_register_obsolete_preference(gui_font_module, "font_name");
prefs_register_string_preference(gui_font_module, "gtk2.font_name", "Font name",
"Font name for packet list, protocol tree, and hex dump panes.", (const char**)(&prefs.gui_font_name));
"Font name for packet list, protocol tree, and hex dump panes. (GTK+)", (const char**)(&prefs.gui_gtk2_font_name));
prefs_register_string_preference(gui_font_module, "qt.font_name", "Font name",
"Font name for packet list, protocol tree, and hex dump panes. (Qt)", (const char**)(&prefs.gui_qt_font_name));
/* User Interface : Colors */
gui_color_module = prefs_register_subtree(gui_module, "Colors", "Colors", NULL);
@ -2571,12 +2574,13 @@ pre_init_prefs(void)
prefs.gui_toolbar_main_style = TB_STYLE_ICONS;
prefs.gui_toolbar_filter_style = TB_STYLE_TEXT;
/* This can be g_freed, so it must be g_mallocated. */
/* XXX - are these the right font names for Qt? */
#ifdef _WIN32
prefs.gui_font_name = g_strdup("Lucida Console 10");
prefs.gui_gtk2_font_name = g_strdup("Lucida Console 10");
#else
prefs.gui_font_name = g_strdup("Monospace 10");
prefs.gui_gtk2_font_name = g_strdup("Monospace 10");
#endif
/* We try to find the best font in the Qt code */
prefs.gui_qt_font_name = g_strdup("");
prefs.gui_marked_fg.pixel = 65535;
prefs.gui_marked_fg.red = 65535;
prefs.gui_marked_fg.green = 65535;

View File

@ -136,7 +136,8 @@ typedef struct _e_prefs {
gboolean gui_hex_dump_highlight_style;
gint gui_toolbar_main_style;
gint gui_toolbar_filter_style;
gchar *gui_font_name;
gchar *gui_gtk2_font_name;
gchar *gui_qt_font_name;
color_t gui_marked_fg;
color_t gui_marked_bg;
color_t gui_ignored_fg;

View File

@ -215,7 +215,7 @@ user_font_apply(void) {
PangoFontDescription *old_r_font = NULL;
/* convert font name to reflect the zoom level */
gui_font_name = font_zoom(prefs.gui_font_name);
gui_font_name = font_zoom(prefs.gui_gtk2_font_name);
if (gui_font_name == NULL) {
/*
* This means the font name isn't an XLFD font name.
@ -359,18 +359,18 @@ void font_init(void)
#endif
/* Try to load the regular fixed-width font */
m_r_font = pango_font_description_from_string(prefs.gui_font_name);
m_r_font = pango_font_description_from_string(prefs.gui_gtk2_font_name);
if (m_r_font == NULL) {
/* XXX - pop this up as a dialog box? no */
fprintf(stderr, "wireshark: Warning: font %s not found - defaulting to Monospace 9\n",
prefs.gui_font_name);
prefs.gui_gtk2_font_name);
if ((m_r_font = pango_font_description_from_string("Monospace 9")) == NULL)
{
fprintf(stderr, "wireshark: Error: font Monospace 9 not found\n");
exit(1);
}
g_free(prefs.gui_font_name);
prefs.gui_font_name = g_strdup("Monospace 9");
g_free(prefs.gui_gtk2_font_name);
prefs.gui_gtk2_font_name = g_strdup("Monospace 9");
}
/* Call this for the side-effects that set_fonts() produces */

View File

@ -2663,8 +2663,8 @@ main(int argc, char *argv[])
#endif
break;
case 'm': /* Fixed-width font for the display */
g_free(prefs_p->gui_font_name);
prefs_p->gui_font_name = g_strdup(optarg);
g_free(prefs_p->gui_gtk2_font_name);
prefs_p->gui_gtk2_font_name = g_strdup(optarg);
break;
case 'n': /* No name resolution */
gbl_resolv_flags.mac_name = FALSE;

View File

@ -45,8 +45,8 @@
#define SAMPLE_MARKED_TEXT "Sample marked packet text\n"
#define SAMPLE_IGNORED_TEXT "Sample ignored packet text\n"
#define SAMPLE_CLIENT_TEXT "Sample TCP stream client text\n"
#define SAMPLE_SERVER_TEXT "Sample TCP stream server text\n"
#define SAMPLE_CLIENT_TEXT "Sample stream client text\n"
#define SAMPLE_SERVER_TEXT "Sample stream server text\n"
#define MFG_IDX 0
#define MBG_IDX 1
#define IFG_IDX 2
@ -96,14 +96,14 @@ font_color_prefs_show(void)
GtkWidget *font_sample, *color_sample, *colorsel;
int i;
const gchar *mt[] = {
"Marked packet foreground", /* MFG_IDX 0*/
"Marked packet background", /* MBG_IDX 1*/
"Ignored packet foreground", /* IFG_IDX 2*/
"Ignored packet background", /* IBG_IDX 3*/
"TCP stream client foreground", /* CFG_IDX 4*/
"TCP stream client background", /* CBG_IDX 5*/
"TCP stream server foreground", /* SFG_IDX 6*/
"TCP stream server background" /* SBG_IDX 7*/
"Marked packet foreground", /* MFG_IDX 0*/
"Marked packet background", /* MBG_IDX 1*/
"Ignored packet foreground", /* IFG_IDX 2*/
"Ignored packet background", /* IBG_IDX 3*/
"Stream client foreground", /* CFG_IDX 4*/
"Stream client background", /* CBG_IDX 5*/
"Stream server foreground", /* SFG_IDX 6*/
"Stream server background" /* SBG_IDX 7*/
};
int mcount = sizeof(mt) / sizeof (gchar *);
GtkTextBuffer *buf;
@ -140,7 +140,7 @@ font_color_prefs_show(void)
ws_gtk_grid_attach_extended(GTK_GRID(main_grid), label, 0, 0, 1, 1, GTK_EXPAND|GTK_FILL, 0, 0,0);
gtk_widget_show(label);
font_button = gtk_font_button_new_with_font(prefs.gui_font_name);
font_button = gtk_font_button_new_with_font(prefs.gui_gtk2_font_name);
gtk_font_button_set_title(GTK_FONT_BUTTON(font_button), "Wireshark: Font");
ws_gtk_grid_attach(GTK_GRID(main_grid), font_button, 1, 0, 1, 1);
gtk_widget_show(font_button);
@ -343,10 +343,10 @@ font_color_prefs_fetch(GtkWidget *w _U_)
* places where there *can* be a bad preference value.
*/
if (font_fetch()) {
if (strcmp(new_font_name, prefs.gui_font_name) != 0) {
if (strcmp(new_font_name, prefs.gui_gtk2_font_name) != 0) {
font_changed = TRUE;
g_free(prefs.gui_font_name);
prefs.gui_font_name = g_strdup(new_font_name);
g_free(prefs.gui_gtk2_font_name);
prefs.gui_gtk2_font_name = g_strdup(new_font_name);
}
}
}

View File

@ -38,6 +38,7 @@ set(QTSHARK_H_SRC
export_dissection_dialog.h
export_object_dialog.h
file_set_dialog.h
font_color_preferences_frame.h
import_text_dialog.h
interface_tree.h
label_stack.h
@ -46,7 +47,6 @@ set(QTSHARK_H_SRC
main_welcome.h
main_window.h
main_window_preferences_frame.h
monospace_font.h
packet_comment_dialog.h
packet_format_group_box.h
packet_list.h
@ -86,6 +86,7 @@ set(QTSHARK_CPP_SRC
export_dissection_dialog.cpp
export_object_dialog.cpp
file_set_dialog.cpp
font_color_preferences_frame.cpp
import_text_dialog.cpp
interface_tree.cpp
label_stack.cpp
@ -96,7 +97,6 @@ set(QTSHARK_CPP_SRC
main_window.cpp
main_window_preferences_frame.cpp
main_window_slots.cpp
monospace_font.cpp
packet_comment_dialog.cpp
packet_format_group_box.cpp
packet_list.cpp
@ -127,6 +127,7 @@ set(QTSHARK_UI
column_preferences_frame.ui
export_object_dialog.ui
file_set_dialog.ui
font_color_preferences_frame.ui
import_text_dialog.ui
layout_preferences_frame.ui
main_welcome.ui

View File

@ -89,6 +89,8 @@ export_object_dialog.cpp export_object_dialog.h: ui_export_object_dialog.h
file_set_dialog.cpp file_set_dialog.h: ui_file_set_dialog.h
font_color_preferences_frame.cpp font_color_preferences_frame.h: ui_font_color_preferences_frame.h
import_text_dialog.cpp import_text_dialog.h: ui_import_text_dialog.h
layout_preferences_frame.cpp layout_preferences_frame.h: ui_layout_preferences_frame.h

View File

@ -34,6 +34,7 @@ GENERATED_NODIST_HEADER_FILES = \
ui_column_preferences_frame.h \
ui_export_object_dialog.h \
ui_file_set_dialog.h \
ui_font_color_preferences_frame.h \
ui_import_text_dialog.h \
ui_layout_preferences_frame.h \
ui_main_welcome.h \
@ -96,6 +97,7 @@ MOC_HDRS = \
export_dissection_dialog.h \
export_object_dialog.h \
file_set_dialog.h \
font_color_preferences_frame.h \
import_text_dialog.h \
interface_tree.h \
label_stack.h \
@ -104,7 +106,6 @@ MOC_HDRS = \
main_welcome.h \
main_window.h \
main_window_preferences_frame.h \
monospace_font.h \
packet_comment_dialog.h \
packet_format_group_box.h \
packet_list.h \
@ -132,6 +133,7 @@ UI_FILES = \
column_preferences_frame.ui \
export_object_dialog.ui \
file_set_dialog.ui \
font_color_preferences_frame.ui \
import_text_dialog.ui \
layout_preferences_frame.ui \
main_welcome.ui \
@ -205,6 +207,7 @@ WIRESHARK_QT_SRC = \
export_dissection_dialog.cpp \
export_object_dialog.cpp \
file_set_dialog.cpp \
font_color_preferences_frame.cpp \
import_text_dialog.cpp \
interface_tree.cpp \
label_stack.cpp \
@ -215,7 +218,6 @@ WIRESHARK_QT_SRC = \
main_window.cpp \
main_window_preferences_frame.cpp \
main_window_slots.cpp \
monospace_font.cpp \
packet_comment_dialog.cpp \
packet_format_group_box.cpp \
packet_list.cpp \

View File

@ -196,7 +196,8 @@ FORMS += main_window.ui \
preferences_dialog.ui \
main_window_preferences_frame.ui \
layout_preferences_frame.ui \
column_preferences_frame.ui
column_preferences_frame.ui \
font_color_preferences_frame.ui
win32 { ## These should be in config.pri ??
!isEmpty(PORTAUDIO_DIR) {
@ -233,7 +234,8 @@ HEADERS += $$HEADERS_WS_C \
preferences_dialog.h \
main_window_preferences_frame.h \
layout_preferences_frame.h \
column_preferences_frame.h
column_preferences_frame.h \
font_color_preferences_frame.h
win32 {
OBJECTS_WS_C = $$SOURCES_WS_C
@ -395,7 +397,6 @@ HEADERS += \
main_status_bar.h \
main_welcome.h \
main_window.h \
monospace_font.h \
packet_list.h \
packet_list_model.h \
packet_list_record.h \
@ -433,7 +434,6 @@ SOURCES += \
main_welcome.cpp \
main_window.cpp \
main_window_slots.cpp \
monospace_font.cpp \
packet_comment_dialog.cpp \
packet_format_group_box.cpp \
packet_list.cpp \
@ -456,4 +456,5 @@ SOURCES += \
preferences_dialog.cpp \
main_window_preferences_frame.cpp \
layout_preferences_frame.cpp \
column_preferences_frame.cpp
column_preferences_frame.cpp \
font_color_preferences_frame.cpp

View File

@ -21,13 +21,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include <glib.h>
#include "color_utils.h"
#include "color.h"
/*
* Initialize a color with R, G, and B values, including any toolkit-dependent
@ -51,12 +47,16 @@ initialize_color(color_t *color, guint16 red, guint16 green, guint16 blue)
return TRUE;
}
// XXX - We probably don't need a class.
ColorUtils::ColorUtils(QWidget *parent) :
QWidget(parent)
ColorUtils::ColorUtils(QObject *parent) :
QObject(parent)
{
}
QColor ColorUtils::fromColorT (color_t *color) {
if (!color) return QColor();
return QColor(color->red >> 8, color->green >> 8, color->blue >> 8);
}
/*
* Editor modelines
*

View File

@ -24,13 +24,22 @@
#ifndef COLOR_UTILS_H
#define COLOR_UTILS_H
#include <QWidget>
#include "config.h"
class ColorUtils : public QWidget
#include <glib.h>
#include "color.h"
#include <QObject>
#include <QColor>
class ColorUtils : public QObject
{
Q_OBJECT
public:
explicit ColorUtils(QWidget *parent = 0);
explicit ColorUtils(QObject *parent = 0);
static QColor fromColorT(color_t *color);
signals:

View File

@ -0,0 +1,230 @@
/* font_color_preferences_frame.cpp
*
* $Id$
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "font_color_preferences_frame.h"
#include "ui_font_color_preferences_frame.h"
#include "color_utils.h"
#include "wireshark_application.h"
#include <QFontDialog>
#include <QColorDialog>
#include <epan/prefs-int.h>
static const char *font_pangrams_[] = {
"Example GIF query packets have jumbo window sizes",
"Lazy badgers move unique waxy jellyfish packets"
};
const int num_font_pangrams_ = (sizeof font_pangrams_ / sizeof font_pangrams_[0]);
FontColorPreferencesFrame::FontColorPreferencesFrame(QWidget *parent) :
QFrame(parent),
ui(new Ui::FontColorPreferencesFrame)
{
ui->setupUi(this);
pref_qt_gui_font_name_ = prefFromPrefPtr(&prefs.gui_qt_font_name);
pref_marked_fg_ = prefFromPrefPtr(&prefs.gui_marked_fg);
pref_marked_bg_ = prefFromPrefPtr(&prefs.gui_marked_bg);
pref_ignored_fg_ = prefFromPrefPtr(&prefs.gui_ignored_fg);
pref_ignored_bg_ = prefFromPrefPtr(&prefs.gui_ignored_bg);
pref_client_fg_ = prefFromPrefPtr(&prefs.st_client_fg);
pref_client_bg_ = prefFromPrefPtr(&prefs.st_client_bg);
pref_server_fg_ = prefFromPrefPtr(&prefs.st_server_fg);
pref_server_bg_ = prefFromPrefPtr(&prefs.st_server_bg);
cur_font_.fromString(pref_qt_gui_font_name_->stashed_val.string);
}
FontColorPreferencesFrame::~FontColorPreferencesFrame()
{
delete ui;
}
void FontColorPreferencesFrame::showEvent(QShowEvent *evt)
{
Q_UNUSED(evt)
GRand *rand_state = g_rand_new();
QString pangram = QString(font_pangrams_[g_rand_int_range(rand_state, 0, num_font_pangrams_)]) + " 0123456789";
ui->fontSampleLineEdit->setText(pangram);
ui->fontSampleLineEdit->setCursorPosition(0);
ui->fontSampleLineEdit->setMinimumWidth(wsApp->monospaceTextSize(pangram.toUtf8().constData()) + wsApp->monospaceTextSize(" "));
g_rand_free(rand_state);
updateWidgets();
}
void FontColorPreferencesFrame::updateWidgets()
{
int margin = style()->pixelMetric(QStyle::PM_LayoutLeftMargin);
ui->fontPushButton->setText(
cur_font_.family() + " " + cur_font_.styleName() + " " +
QString::number(cur_font_.pointSizeF(), 'f', 1));
ui->fontSampleLineEdit->setFont(cur_font_);
QString line_edit_ss = QString("QLineEdit { margin-left: %1px; }").arg(margin);
ui->fontSampleLineEdit->setStyleSheet(line_edit_ss);
QString color_button_ss =
"QPushButton {"
" border: 1px solid palette(Dark);"
" background-color: %1;"
" margin-left: %2px;"
"}";
QString sample_text_ss =
"QLineEdit {"
" color: %1;"
" background-color: %2;"
"}";
ui->markedFGPushButton->setStyleSheet(color_button_ss.arg(
ColorUtils::fromColorT(&pref_marked_fg_->stashed_val.color).name())
.arg(margin));
ui->markedBGPushButton->setStyleSheet(color_button_ss.arg(
ColorUtils::fromColorT(&pref_marked_bg_->stashed_val.color).name())
.arg(0));
ui->markedSampleLineEdit->setStyleSheet(sample_text_ss.arg(
ColorUtils::fromColorT(&pref_marked_fg_->stashed_val.color).name(),
ColorUtils::fromColorT(&pref_marked_bg_->stashed_val.color).name()));
ui->markedSampleLineEdit->setFont(cur_font_);
ui->ignoredFGPushButton->setStyleSheet(color_button_ss.arg(
ColorUtils::fromColorT(&pref_ignored_fg_->stashed_val.color).name())
.arg(margin));
ui->ignoredBGPushButton->setStyleSheet(color_button_ss.arg(
ColorUtils::fromColorT(&pref_ignored_bg_->stashed_val.color).name())
.arg(0));
ui->ignoredSampleLineEdit->setStyleSheet(sample_text_ss.arg(
ColorUtils::fromColorT(&pref_ignored_fg_->stashed_val.color).name(),
ColorUtils::fromColorT(&pref_ignored_bg_->stashed_val.color).name()));
ui->ignoredSampleLineEdit->setFont(cur_font_);
ui->clientFGPushButton->setStyleSheet(color_button_ss.arg(
ColorUtils::fromColorT(&pref_client_fg_->stashed_val.color).name())
.arg(margin));
ui->clientBGPushButton->setStyleSheet(color_button_ss.arg(
ColorUtils::fromColorT(&pref_client_bg_->stashed_val.color).name())
.arg(0));
ui->clientSampleLineEdit->setStyleSheet(sample_text_ss.arg(
ColorUtils::fromColorT(&pref_client_fg_->stashed_val.color).name(),
ColorUtils::fromColorT(&pref_client_bg_->stashed_val.color).name()));
ui->clientSampleLineEdit->setFont(cur_font_);
ui->serverFGPushButton->setStyleSheet(color_button_ss.arg(
ColorUtils::fromColorT(&pref_server_fg_->stashed_val.color).name())
.arg(margin));
ui->serverBGPushButton->setStyleSheet(color_button_ss.arg(
ColorUtils::fromColorT(&pref_server_bg_->stashed_val.color).name())
.arg(0));
ui->serverSampleLineEdit->setStyleSheet(sample_text_ss.arg(
ColorUtils::fromColorT(&pref_server_fg_->stashed_val.color).name(),
ColorUtils::fromColorT(&pref_server_bg_->stashed_val.color).name()));
ui->serverSampleLineEdit->setFont(cur_font_);
}
void FontColorPreferencesFrame::changeColor(pref_t *pref)
{
QColorDialog color_dlg;
color_dlg.setCurrentColor(QColor(
pref->stashed_val.color.red >> 8,
pref->stashed_val.color.green >> 8,
pref->stashed_val.color.blue >> 8
));
if (color_dlg.exec() == QDialog::Accepted) {
QColor cc = color_dlg.currentColor();
pref->stashed_val.color.red = cc.red() << 8 | cc.red();
pref->stashed_val.color.green = cc.green() << 8 | cc.green();
pref->stashed_val.color.blue = cc.blue() << 8 | cc.blue();
updateWidgets();
}
}
#include <QDebug>
void FontColorPreferencesFrame::on_fontPushButton_clicked()
{
bool ok;
QFont new_font = QFontDialog::getFont(&ok, cur_font_, this, "Wireshark: Font");
if (ok) {
g_free(pref_qt_gui_font_name_->stashed_val.string);
pref_qt_gui_font_name_->stashed_val.string = g_strdup(new_font.toString().toUtf8().constData());
cur_font_ = new_font;
updateWidgets();
}
}
void FontColorPreferencesFrame::on_markedFGPushButton_clicked()
{
changeColor(pref_marked_fg_);
}
void FontColorPreferencesFrame::on_markedBGPushButton_clicked()
{
changeColor(pref_marked_bg_);
}
void FontColorPreferencesFrame::on_ignoredFGPushButton_clicked()
{
changeColor(pref_ignored_fg_);
}
void FontColorPreferencesFrame::on_ignoredBGPushButton_clicked()
{
changeColor(pref_ignored_bg_);
}
void FontColorPreferencesFrame::on_clientFGPushButton_clicked()
{
changeColor(pref_client_fg_);
}
void FontColorPreferencesFrame::on_clientBGPushButton_clicked()
{
changeColor(pref_client_bg_);
}
void FontColorPreferencesFrame::on_serverFGPushButton_clicked()
{
changeColor(pref_server_fg_);
}
void FontColorPreferencesFrame::on_serverBGPushButton_clicked()
{
changeColor(pref_server_bg_);
}
/*
* Editor modelines
*
* Local Variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* ex: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/

View File

@ -0,0 +1,79 @@
/* font_color_preferences_frame.h
*
* $Id$
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef FONT_COLOR_PREFERENCES_FRAME_H
#define FONT_COLOR_PREFERENCES_FRAME_H
#include "preferences_dialog.h"
#include <QFrame>
#include <QFont>
namespace Ui {
class FontColorPreferencesFrame;
}
class FontColorPreferencesFrame : public QFrame
{
Q_OBJECT
public:
explicit FontColorPreferencesFrame(QWidget *parent = 0);
~FontColorPreferencesFrame();
protected:
void showEvent(QShowEvent *evt);
private:
Ui::FontColorPreferencesFrame *ui;
pref_t *pref_qt_gui_font_name_;
pref_t *pref_marked_fg_;
pref_t *pref_marked_bg_;
pref_t *pref_ignored_fg_;
pref_t *pref_ignored_bg_;
pref_t *pref_client_fg_;
pref_t *pref_client_bg_;
pref_t *pref_server_fg_;
pref_t *pref_server_bg_;
QFont cur_font_;
void updateWidgets();
void changeColor(pref_t *pref);
private slots:
void on_fontPushButton_clicked();
void on_markedFGPushButton_clicked();
void on_markedBGPushButton_clicked();
void on_ignoredFGPushButton_clicked();
void on_ignoredBGPushButton_clicked();
void on_clientFGPushButton_clicked();
void on_clientBGPushButton_clicked();
void on_serverFGPushButton_clicked();
void on_serverBGPushButton_clicked();
};
#endif // FONT_COLOR_PREFERENCES_FRAME_H

View File

@ -0,0 +1,215 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FontColorPreferencesFrame</class>
<widget class="QFrame" name="FontColorPreferencesFrame">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>540</width>
<height>280</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>540</width>
<height>280</height>
</size>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Main window font:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="fontPushButton">
<property name="text">
<string>Select Font</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLineEdit" name="fontSampleLineEdit">
<property name="text">
<string/>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Colors:</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QPushButton" name="ignoredBGPushButton">
<property name="styleSheet">
<string notr="true">QPushButton { border: 1px solid palette(Dark); }</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="ignoredSampleLineEdit">
<property name="text">
<string>Sample ignored packet text</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="clientBGPushButton">
<property name="styleSheet">
<string notr="true">QPushButton { border: 1px solid palette(Dark); }</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="markedSampleLineEdit">
<property name="text">
<string>Sample marked packet text</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="clientFGPushButton">
<property name="styleSheet">
<string notr="true">QPushButton { border: 1px solid palette(Dark); }</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="clientSampleLineEdit">
<property name="text">
<string>Sample stream client text</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="serverFGPushButton">
<property name="styleSheet">
<string notr="true">QPushButton { border: 1px solid palette(Dark); }</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLineEdit" name="serverSampleLineEdit">
<property name="text">
<string>Sample stream server text</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="markedFGPushButton">
<property name="styleSheet">
<string notr="true">QPushButton { border: 1px solid palette(Dark); }</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="ignoredFGPushButton">
<property name="styleSheet">
<string notr="true">QPushButton { border: 1px solid palette(Dark); }</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="serverBGPushButton">
<property name="styleSheet">
<string notr="true">QPushButton { border: 1px solid palette(Dark); }</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="markedBGPushButton">
<property name="styleSheet">
<string notr="true">QPushButton { border: 1px solid palette(Dark); }</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>178</width>
<height>13</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -119,8 +119,6 @@
#include <epan/crypt/airpdcap_ws.h>
#include "monospace_font.h"
#include <QDebug>
#include <QDateTime>
#include <QTextCodec>
@ -1002,7 +1000,7 @@ int main(int argc, char *argv[])
// #endif
// g_free(rc_file);
font_init();
wsApp->setMonospaceFont(prefs.gui_qt_font_name);
////////
@ -1022,25 +1020,25 @@ int main(int argc, char *argv[])
////////
switch (user_font_apply()) {
case FA_SUCCESS:
break;
case FA_FONT_NOT_RESIZEABLE:
/* "user_font_apply()" popped up an alert box. */
/* turn off zooming - font can't be resized */
case FA_FONT_NOT_AVAILABLE:
/* XXX - did we successfully load the un-zoomed version earlier?
If so, this *probably* means the font is available, but not at
this particular zoom level, but perhaps some other failure
occurred; I'm not sure you can determine which is the case,
however. */
/* turn off zooming - zoom level is unavailable */
default:
/* in any other case than FA_SUCCESS, turn off zooming */
// recent.gui_zoom_level = 0;
/* XXX: would it be a good idea to disable zooming (insensitive GUI)? */
break;
}
// switch (user_font_apply()) {
// case FA_SUCCESS:
// break;
// case FA_FONT_NOT_RESIZEABLE:
// /* "user_font_apply()" popped up an alert box. */
// /* turn off zooming - font can't be resized */
// case FA_FONT_NOT_AVAILABLE:
// /* XXX - did we successfully load the un-zoomed version earlier?
// If so, this *probably* means the font is available, but not at
// this particular zoom level, but perhaps some other failure
// occurred; I'm not sure you can determine which is the case,
// however. */
// /* turn off zooming - zoom level is unavailable */
// default:
// /* in any other case than FA_SUCCESS, turn off zooming */
//// recent.gui_zoom_level = 0;
// /* XXX: would it be a good idea to disable zooming (insensitive GUI)? */
// break;
// }
////////
color_filters_init();

View File

@ -1,182 +0,0 @@
/* monospace_font.cpp
*
* $Id$
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "monospace_font.h"
#include <QFontMetrics>
#include <QString>
#include <QStringList>
#include <QDebug>
//
// XXX We should probably move this to wsApp.
//
//MonospaceFont::MonospaceFont(QObject *parent) :
// QFont(parent)
//{
//}
QFont mono_regular_font_, mono_bold_font_;
//void MonospaceFont::propagate() {
// emit(monospaceFontChanged(self));
//}
// http://en.wikipedia.org/wiki/Category:Monospaced_typefaces
#define WIN_DEF_FONT "Consolas"
#define WIN_ALT_FONTS "Lucida Console"
#define OSX_DEF_FONT "Menlo"
#define OSX_ALT_FONTS "Monaco"
#define X11_DEF_FONT "Bitstream Vera Sans Mono"
#define X11_ALT_FONTS "Liberation Mono" << "DejaVu Sans Mono"
#define FALLBACK_FONTS "Lucida Sans Typewriter" << "Inconsolata" << "Droid Sans Mono" << "Andale Mono" << "Courier New" << "monospace"
void
font_init(void) {
QStringList substitutes;
// Try to pick the latest, shiniest fixed-width font for our OS.
#if defined(Q_WS_WIN)
#define DEF_FONT WIN_DEF_FONT
#define FONT_SIZE_ADJUST 2
substitutes = QStringList() << WIN_ALT_FONTS << OSX_DEF_FONT << OSX_ALT_FONTS << X11_DEF_FONT << X11_ALT_FONTS << FALLBACK_FONTS;
#elif defined(Q_WS_MAC)
#define DEF_FONT OSX_DEF_FONT
#define FONT_SIZE_ADJUST 0
substitutes = QStringList() << OSX_ALT_FONTS << WIN_DEF_FONT << WIN_ALT_FONTS << X11_DEF_FONT << X11_ALT_FONTS << FALLBACK_FONTS;
#else
#define DEF_FONT X11_DEF_FONT
#define FONT_SIZE_ADJUST 0
substitutes = QStringList() << X11_ALT_FONTS << WIN_DEF_FONT << WIN_ALT_FONTS << OSX_DEF_FONT << OSX_ALT_FONTS << FALLBACK_FONTS;
#endif
mono_regular_font_.setFamily(DEF_FONT);
mono_regular_font_.insertSubstitutions(DEF_FONT, substitutes);
mono_regular_font_.setPointSize(wsApp->font().pointSize() + FONT_SIZE_ADJUST);
#if QT_VERSION >= 0x040700
mono_bold_font_.setStyleHint(QFont::Monospace);
#else
mono_bold_font_.setStyleHint(QFont::TypeWriter);
#endif
mono_bold_font_.setFamily(DEF_FONT);
mono_bold_font_.insertSubstitutions(DEF_FONT, substitutes);
mono_bold_font_.setPointSize(wsApp->font().pointSize() + FONT_SIZE_ADJUST);
#if QT_VERSION >= 0x040700
mono_bold_font_.setStyleHint(QFont::Monospace);
#else
mono_bold_font_.setStyleHint(QFont::TypeWriter);
#endif
mono_bold_font_.setWeight(QFont::Bold);
}
fa_ret_t
user_font_apply(void) {
// char *gui_font_name;
// PangoFontDescription *new_r_font, *new_b_font;
// PangoFontDescription *old_r_font = NULL, *old_b_font = NULL;
/* convert font name to reflect the zoom level */
// gui_font_name = font_zoom(prefs.gui_font_name);
// if (gui_font_name == NULL) {
// /*
// * This means the font name isn't an XLFD font name.
// * We just report that for now as a font not available in
// * multiple sizes.
// */
// simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
// "Your current font isn't available in any other sizes.\n");
// return FA_FONT_NOT_RESIZEABLE;
// }
// /* load normal and bold font */
// new_r_font = pango_font_description_from_string(gui_font_name);
// new_b_font = pango_font_description_copy(new_r_font);
// pango_font_description_set_weight(new_b_font, PANGO_WEIGHT_BOLD);
// if (new_r_font == NULL || new_b_font == NULL) {
// /* We're no longer using the new fonts; unreference them. */
// if (new_r_font != NULL)
// pango_font_description_free(new_r_font);
// if (new_b_font != NULL)
// pango_font_description_free(new_b_font);
// g_free(gui_font_name);
// /* We let our caller pop up a dialog box, as the error message
// depends on the context (did they zoom in or out, or did they
// do something else? */
// return FA_FONT_NOT_AVAILABLE;
// }
// /* the font(s) seem to be ok */
// packet_list_set_font(new_r_font);
// set_ptree_font_all(new_r_font);
// old_r_font = m_r_font;
// old_b_font = m_b_font;
// set_fonts(new_r_font, new_b_font);
// /* Redraw the packet bytes windows. */
// redraw_packet_bytes_all();
// /* Redraw the "Follow TCP Stream" windows. */
// follow_tcp_redraw_all();
// /* We're no longer using the old fonts; unreference them. */
// if (old_r_font != NULL)
// pango_font_description_free(old_r_font);
// if (old_b_font != NULL)
// pango_font_description_free(old_b_font);
// g_free(gui_font_name);
return FA_SUCCESS;
}
QFont WiresharkApplication::monospaceFont(bool bold)
{
return bold ? mono_bold_font_ : mono_regular_font_;
}
int get_monospace_text_size(const char *str, bool regular) {
QFontMetrics *fm;
if (regular)
fm = new QFontMetrics(mono_regular_font_);
else
fm = new QFontMetrics(mono_bold_font_);
return fm->width(str);
}
/*
* Editor modelines
*
* Local Variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* ex: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/

View File

@ -1,77 +0,0 @@
/* monospace_font.h
*
* $Id$
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MONOSPACE_FONT_H
#define MONOSPACE_FONT_H
#include "wireshark_application.h"
#include <QFont>
//class MonospaceFont : public QFont
//{
// Q_OBJECT
//public:
// explicit MonospaceFont(QObject *parent = 0);
// void propagate(void);
//signals:
// void monospaceFontChanged(QFont);
//public slots:
//};
/** Init the application and user fonts at program start. */
extern void font_init(void);
/** Return value from font_apply() */
typedef enum {
FA_SUCCESS, /**< function succeeded */
FA_FONT_NOT_RESIZEABLE, /**< the chosen font isn't resizable */
FA_FONT_NOT_AVAILABLE /**< the chosen font isn't available */
} fa_ret_t;
/** Applies a new user font, corresponding to the preferences font name and recent zoom level.
* Will also redraw the screen.
*
* @return if the new font could be set or not
*/
extern fa_ret_t user_font_apply(void);
extern int get_monospace_text_size(const char *str, bool regular);
#endif // MONOSPACE_FONT_H
/*
* Editor modelines
*
* Local Variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* ex: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/

View File

@ -33,8 +33,8 @@
#include <epan/packet.h>
#include "packet_list.h"
#include "monospace_font.h"
#include "proto_tree.h"
#include "wireshark_application.h"
#include "qt_ui_utils.h"
@ -395,9 +395,9 @@ void PacketList::showEvent (QShowEvent *event) {
fmt = get_column_format(i);
long_str = get_column_width_string(fmt, i);
if (long_str) {
col_width = get_monospace_text_size(long_str, TRUE);
col_width = wsApp->monospaceTextSize(long_str);
} else {
col_width = get_monospace_text_size(MIN_COL_WIDTH_STR, TRUE);
col_width = wsApp->monospaceTextSize(MIN_COL_WIDTH_STR);
}
setColumnWidth(i, col_width);
}

View File

@ -220,6 +220,7 @@ void PreferencesDialog::showEvent(QShowEvent *evt)
pd_ui_->prefsTree->resizeColumnToContents(0);
new_prefs_tree_width += pd_ui_->prefsTree->columnWidth(0);
pd_ui_->prefsTree->setMinimumWidth(new_prefs_tree_width);
sizes[1] += sizes[0] - new_prefs_tree_width;
sizes[0] = new_prefs_tree_width;
pd_ui_->splitter->setSizes(sizes);
@ -674,6 +675,7 @@ void PreferencesDialog::on_buttonBox_accepted()
// prefs_airpcap_update();
#endif
wsApp->setMonospaceFont(prefs.gui_qt_font_name);
wsApp->emitAppSignal(WiresharkApplication::PreferencesChanged);
/* Now destroy the "Preferences" dialog. */

View File

@ -55,9 +55,6 @@
<property name="text">
<string>Font and Colors</string>
</property>
<property name="flags">
<set>ItemIsDragEnabled|ItemIsUserCheckable</set>
</property>
</item>
</item>
<item>
@ -119,7 +116,7 @@
<widget class="MainWindowPreferencesFrame" name="appearanceFrame"/>
<widget class="LayoutPreferencesFrame" name="layoutFrame"/>
<widget class="ColumnPreferencesFrame" name="columnFrame"/>
<widget class="QFrame" name="fontandcolorFrame"/>
<widget class="FontColorPreferencesFrame" name="fontandcolorFrame"/>
<widget class="QFrame" name="captureFrame"/>
<widget class="QFrame" name="filterFrame"/>
<widget class="QFrame" name="nameresolutionFrame"/>
@ -217,6 +214,12 @@
<header>column_preferences_frame.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>FontColorPreferencesFrame</class>
<extends>QFrame</extends>
<header>font_color_preferences_frame.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>

View File

@ -44,16 +44,17 @@
# include "ui/win32/console_win32.h"
#endif /* _WIN32 */
#include <QDesktopServices>
#include <QDir>
#include <QTimer>
#include <QEvent>
#include <QFileOpenEvent>
#include <QDesktopServices>
#include <QFontMetrics>
#include <QTimer>
#include <QUrl>
#ifdef Q_WS_WIN
#include <QLibrary>
#include <QDebug>
#include <QLibrary>
#endif
WiresharkApplication *wsApp = NULL;
@ -151,6 +152,8 @@ extern "C" void menu_recent_file_write_all(FILE *rf) {
}
}
extern gboolean main_do_quit(void) {
WiresharkApplication::quit();
return FALSE;
@ -306,6 +309,70 @@ void WiresharkApplication::helpTopicAction(topic_action_e action)
}
}
// http://en.wikipedia.org/wiki/Category:Monospaced_typefaces
#define WIN_DEF_FONT "Consolas"
#define WIN_ALT_FONTS "Lucida Console"
#define OSX_DEF_FONT "Menlo"
#define OSX_ALT_FONTS "Monaco"
#define X11_DEF_FONT "Bitstream Vera Sans Mono"
#define X11_ALT_FONTS "Liberation Mono" << "DejaVu Sans Mono"
#define FALLBACK_FONTS "Lucida Sans Typewriter" << "Inconsolata" << "Droid Sans Mono" << "Andale Mono" << "Courier New" << "monospace"
void WiresharkApplication::setMonospaceFont(const char *font_string) {
if (font_string && strlen(font_string) > 0) {
mono_regular_font_.fromString(font_string);
mono_bold_font_ = QFont(mono_regular_font_);
mono_bold_font_.setBold(true);
return;
}
QStringList substitutes;
// Try to pick the latest, shiniest fixed-width font for our OS.
#if defined(Q_WS_WIN)
#define DEF_FONT WIN_DEF_FONT
#define FONT_SIZE_ADJUST 2
substitutes = QStringList() << WIN_ALT_FONTS << OSX_DEF_FONT << OSX_ALT_FONTS << X11_DEF_FONT << X11_ALT_FONTS << FALLBACK_FONTS;
#elif defined(Q_WS_MAC)
#define DEF_FONT OSX_DEF_FONT
#define FONT_SIZE_ADJUST 0
substitutes = QStringList() << OSX_ALT_FONTS << WIN_DEF_FONT << WIN_ALT_FONTS << X11_DEF_FONT << X11_ALT_FONTS << FALLBACK_FONTS;
#else
#define DEF_FONT X11_DEF_FONT
#define FONT_SIZE_ADJUST 0
substitutes = QStringList() << X11_ALT_FONTS << WIN_DEF_FONT << WIN_ALT_FONTS << OSX_DEF_FONT << OSX_ALT_FONTS << FALLBACK_FONTS;
#endif
mono_regular_font_.setFamily(DEF_FONT);
mono_regular_font_.insertSubstitutions(DEF_FONT, substitutes);
mono_regular_font_.setPointSize(wsApp->font().pointSize() + FONT_SIZE_ADJUST);
mono_regular_font_.setBold(false);
mono_bold_font_ = QFont(mono_regular_font_);
mono_bold_font_.setBold(true);
g_free(prefs.gui_qt_font_name);
prefs.gui_qt_font_name = g_strdup(mono_regular_font_.toString().toUtf8().constData());
}
int WiresharkApplication::monospaceTextSize(const char *str, bool bold)
{
QFontMetrics *fm;
if (bold)
fm = new QFontMetrics(mono_bold_font_);
else
fm = new QFontMetrics(mono_regular_font_);
return fm->width(str);
}
QFont WiresharkApplication::monospaceFont(bool bold)
{
return bold ? mono_bold_font_ : mono_regular_font_;
}
void WiresharkApplication::setConfigurationProfile(const gchar *profile_name)
{
char *gdp_path, *dp_path;

View File

@ -37,8 +37,9 @@
#include "ui/help_url.h"
#include <QApplication>
#include <QList>
#include <QFileInfo>
#include <QFont>
#include <QList>
#include <QThread>
// Recent items:
@ -81,6 +82,8 @@ public:
void setLastOpenDir(QString *dir_str);
void helpTopicAction(topic_action_e action);
QFont monospaceFont(bool bold = false);
void setMonospaceFont(const char *font_string);
int monospaceTextSize(const char *str, bool bold = false);
void setConfigurationProfile(const gchar *profile_name);
@ -88,6 +91,8 @@ private:
void prefsToCaptureOpts();
bool initialized_;
QFont mono_regular_font_;
QFont mono_bold_font_;
QTimer *recent_timer_;
QList<QString> pending_open_files_;