view libgui/src/resource-manager.h @ 29498:5384bb4efc51

rearrange default lexer settings and add second color mode to gui editor * default-qt-settings.in: remove all lexer related default settings * gui-preferences-ed.h: add constants related to the number of lexer styles, remove obsolete preference ed_highlight_current_line_color * gui-settings.cc (get_color_value): move detecting the color from the QVaraiant drom color_value into this separate function (required for reading the default lexer settings); (color_value); see get_color_value; (set_color_value): shorter access to QStringList elements * gui-settings.h: new method get_color_value, new constant for the magenta color indicating same color as the default value in the editor styles * file-editor-tab.cc (file_edito_tab): read lexer settings depending on the current color mode, determine color of current line depending on background color (no more user pref) * octave-qscintilla.cc (set_selection_marker_color): increase alpha value for highlighted occurrences of double clicked word * resource-manager.cc (get_valid_lexer_styles): moved this method from settings_dialog (static) to normal method here; (copy_font_attributes): private method for copying attributes from one font to another font (read_lexer_settings): take color mode into consideration, if lexer settings not found in settings file, take defaults from the lexer, not from octaves default settings file, and write them to the settings file related to the selected color mode * resource-manager.h: new methods get_valid_lexer_styles, copy_font_attributes and new arguments for read_lexer_settings * settings-dialog.cc (get_valid_lexer_styles) moved static method into non-static in resource_manager; (settings_dialog): remove settings for current editor line color; move lexer definition and reading related settings into separate new slot update_editor_lexers, add color mode checkbox and connect state change to update_editor_lexers; (update_editor_lexers): definition of lexers for each language and call update_lexer for the specific actions; (update_lexer): call rmgr.read_lexer_settings, i.e., read settings or get default values from lexer check whether the language tabs in the settings dialog have to be created or updated (due to color mode change), call get_lexer_settings in the first and update the color picker in the second case; (get_lexer_settings, renamed from read_lexer_settings): create the language tab and fill in the lexer values (write_lexer_settings): new argument color mode, write settings into the related section into the settings file; (write_changed_settings): write the editor color mode into the settings, remove editor current line color * settings-dialog.h: new methods update_editor_lexers, update_lexer, renamed read_lexer_settings into get_lexer_settings, new arguments for write_lexer_settings, removed class variable for editor current line color * settings-dialog.ui: added checkbox for editor color mode, removed color picker for editor current line color
author Torsten Lilge <ttl-octave@mailbox.org>
date Tue, 06 Apr 2021 21:26:52 +0200
parents 7854d5752dd2
children 730cac3d6d5a
line wrap: on
line source

////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2021 The Octave Project Developers
//
// See the file COPYRIGHT.md in the top-level directory of this
// distribution or <https://octave.org/copyright/>.
//
// This file is part of Octave.
//
// Octave 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 3 of the License, or
// (at your option) any later version.
//
// Octave 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 Octave; see the file COPYING.  If not, see
// <https://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////

#if ! defined (octave_resource_manager_h)
#define octave_resource_manager_h 1

#include <QComboBox>
#include <QIcon>
#include <QPointer>
#include <Qsci/qscilexer.h>
#include <QTranslator>
#include <QTemporaryFile>

#include "gui-settings.h"

namespace octave
{
  class resource_manager : public QObject
  {
    Q_OBJECT

  protected:

  public:

    resource_manager (void);

    // No copying!

    resource_manager (const resource_manager&) = delete;

    resource_manager& operator = (const resource_manager&) = delete;

    ~resource_manager ();

    QString get_gui_translation_dir (void);

    void config_translators (QTranslator *qt_tr, QTranslator *qsci_tr,
                             QTranslator *gui_tr);

    gui_settings * get_settings (void) const;

    gui_settings * get_default_settings (void) const;

    QString get_settings_directory (void);

    QString get_settings_file (void);

    QString get_default_font_family (void);

    QStringList get_default_font (void);

    QPointer<QTemporaryFile>
    create_tmp_file (const QString& extension = QString (),
                     const QString& contents = QString ());

    void remove_tmp_file (QPointer<QTemporaryFile> tmp_file);

    void reload_settings (void);

#if defined (HAVE_QSCINTILLA)
    int get_valid_lexer_styles (QsciLexer *lexer, int *styles);
    void read_lexer_settings (QsciLexer *lexer, gui_settings *settings, int mode = 0);
#endif

    void set_settings (const QString& file);

    bool update_settings_key (const QString& new_key, const QString& old_key);

    bool is_first_run (void) const;

    void update_network_settings (void);

    QIcon icon (const QString& icon_name, bool fallback = true);

    void get_codecs (QStringList *codecs);

    void combo_encoding (QComboBox *combo, const QString& current = QString ());

  private:

    /*!
     * Copys the attributes bold, italic and underline from QFont
     * @p attr to the font @p base and returns the result without
     * changing @p base,
     * @param attr QFont with the desired attributes
     * @param base QFont with desired family and size
    */
    QFont copy_font_attributes (const QFont& attr, const QFont& base) const;

    QString m_settings_directory;

    QString m_settings_file;

    gui_settings *m_settings;

    gui_settings *m_default_settings;

    QList<QTemporaryFile *> m_temporary_files;
  };
}

#endif