Add the ability for shownames to be outlined (#939)
* showname text outline, partial messagebox outline code * your honor i plead oopsie daisies * Focus down code, add config hookups * remove extraneous qDebug calls
This commit is contained in:
		
							parent
							
								
									a8b28f5070
								
							
						
					
					
						commit
						b48ca2455a
					
				
							
								
								
									
										32
									
								
								include/aotextboxwidgets.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								include/aotextboxwidgets.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,32 @@
 | 
			
		||||
#ifndef AOTEXTBOXWIDGETS_H
 | 
			
		||||
#define AOTEXTBOXWIDGETS_H
 | 
			
		||||
 | 
			
		||||
#include <QAbstractTextDocumentLayout>
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
#include <QLabel>
 | 
			
		||||
#include <QPaintEvent>
 | 
			
		||||
#include <QPainter>
 | 
			
		||||
#include <QPainterPath>
 | 
			
		||||
#include <QTextEdit>
 | 
			
		||||
 | 
			
		||||
class AOChatboxLabel : public QLabel {
 | 
			
		||||
  Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  AOChatboxLabel(QWidget *parent);
 | 
			
		||||
  void paintEvent(QPaintEvent *event);
 | 
			
		||||
 | 
			
		||||
  void setOutlineColor(QColor color) { outline_color = color; };
 | 
			
		||||
  void setOutlineWidth(int width) { outline_width = width; };
 | 
			
		||||
  void setTextColor(QColor color) { text_color = color; };
 | 
			
		||||
  void setIsOutlined(bool outlined) { is_outlined = outlined; };
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
private:
 | 
			
		||||
  QColor outline_color;
 | 
			
		||||
  QColor text_color;
 | 
			
		||||
  int outline_width = 1;
 | 
			
		||||
  bool is_outlined = false;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // AOTEXTBOXWIDGETS_H
 | 
			
		||||
@ -7,24 +7,25 @@
 | 
			
		||||
#include "aocharbutton.h"
 | 
			
		||||
#include "aoclocklabel.h"
 | 
			
		||||
#include "aoemotebutton.h"
 | 
			
		||||
#include "aoemotepreview.h"
 | 
			
		||||
#include "aoevidencebutton.h"
 | 
			
		||||
#include "aoevidencedisplay.h"
 | 
			
		||||
#include "aoimage.h"
 | 
			
		||||
#include "aolayer.h"
 | 
			
		||||
#include "aomusicplayer.h"
 | 
			
		||||
#include "widgets/aooptionsdialog.h"
 | 
			
		||||
#include "aopacket.h"
 | 
			
		||||
#include "aosfxplayer.h"
 | 
			
		||||
#include "aotextarea.h"
 | 
			
		||||
#include "aotextboxwidgets.h"
 | 
			
		||||
#include "chatlogpiece.h"
 | 
			
		||||
#include "datatypes.h"
 | 
			
		||||
#include "debug_functions.h"
 | 
			
		||||
#include "eventfilters.h"
 | 
			
		||||
#include "file_functions.h"
 | 
			
		||||
#include "hardware_functions.h"
 | 
			
		||||
#include "lobby.h"
 | 
			
		||||
#include "scrolltext.h"
 | 
			
		||||
#include "eventfilters.h"
 | 
			
		||||
#include "aoemotepreview.h"
 | 
			
		||||
#include "widgets/aooptionsdialog.h"
 | 
			
		||||
 | 
			
		||||
#include <QCheckBox>
 | 
			
		||||
#include <QCloseEvent>
 | 
			
		||||
@ -145,7 +146,9 @@ public:
 | 
			
		||||
 | 
			
		||||
  // actual operation of setting the font on a widget
 | 
			
		||||
  void set_qfont(QWidget *widget, QString class_name, QFont font,
 | 
			
		||||
                 QColor f_color = Qt::black, bool bold = false);
 | 
			
		||||
                 QColor f_color = Qt::black, bool bold = false,
 | 
			
		||||
                 bool outlined = false, QColor outline_color = QColor(0, 0, 0),
 | 
			
		||||
                 int outline_width = 1);
 | 
			
		||||
 | 
			
		||||
  // helper function that calls above function on the relevant widgets
 | 
			
		||||
  void set_fonts(QString p_char = "");
 | 
			
		||||
@ -654,7 +657,7 @@ private:
 | 
			
		||||
  BackgroundLayer *ui_vp_desk;
 | 
			
		||||
  AOEvidenceDisplay *ui_vp_evidence_display;
 | 
			
		||||
  AOImage *ui_vp_chatbox;
 | 
			
		||||
  QLabel *ui_vp_showname;
 | 
			
		||||
  AOChatboxLabel *ui_vp_showname;
 | 
			
		||||
  InterfaceLayer *ui_vp_chat_arrow;
 | 
			
		||||
  QTextEdit *ui_vp_message;
 | 
			
		||||
  SplashLayer *ui_vp_testimony;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										37
									
								
								src/aotextboxwidgets.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/aotextboxwidgets.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,37 @@
 | 
			
		||||
#include "aotextboxwidgets.h"
 | 
			
		||||
 | 
			
		||||
AOChatboxLabel::AOChatboxLabel(QWidget *parent) : QLabel(parent) {}
 | 
			
		||||
 | 
			
		||||
void AOChatboxLabel::paintEvent(QPaintEvent *event)
 | 
			
		||||
{
 | 
			
		||||
  if (is_outlined) {
 | 
			
		||||
    QBrush brush;
 | 
			
		||||
    QPen pen;
 | 
			
		||||
    QPointF baseline(outline_width, fontMetrics().height());
 | 
			
		||||
 | 
			
		||||
    // Set up brush (base text)
 | 
			
		||||
    brush.setColor(text_color);
 | 
			
		||||
    brush.setStyle(Qt::SolidPattern);
 | 
			
		||||
 | 
			
		||||
    // Set up outline
 | 
			
		||||
    pen.setColor(outline_color);
 | 
			
		||||
    pen.setWidthF(outline_width);
 | 
			
		||||
 | 
			
		||||
    QPainterPath path;
 | 
			
		||||
    path.addText(baseline, font(), text());
 | 
			
		||||
 | 
			
		||||
    QPainter painter(this);
 | 
			
		||||
    painter.setRenderHint(QPainter::Antialiasing);
 | 
			
		||||
    // draw outline
 | 
			
		||||
    painter.setPen(pen);
 | 
			
		||||
    painter.drawPath(path);
 | 
			
		||||
    // remove outline pen, then draw text on top
 | 
			
		||||
    painter.setPen(Qt::NoPen);
 | 
			
		||||
    painter.setBrush(brush);
 | 
			
		||||
    painter.drawPath(path);
 | 
			
		||||
  }
 | 
			
		||||
  else {
 | 
			
		||||
    // Use the default renderer
 | 
			
		||||
    QLabel::paintEvent(event);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -80,7 +80,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
 | 
			
		||||
  ui_vp_sticker->setAttribute(Qt::WA_TransparentForMouseEvents);
 | 
			
		||||
  ui_vp_sticker->setObjectName("ui_vp_sticker");
 | 
			
		||||
 | 
			
		||||
  ui_vp_showname = new QLabel(ui_vp_chatbox);
 | 
			
		||||
  ui_vp_showname = new AOChatboxLabel(ui_vp_chatbox);
 | 
			
		||||
  ui_vp_showname->setObjectName("ui_vp_showname");
 | 
			
		||||
  ui_vp_showname->setAlignment(Qt::AlignLeft);
 | 
			
		||||
  ui_vp_chat_arrow = new InterfaceLayer(this, ao_app);
 | 
			
		||||
@ -1187,8 +1187,27 @@ void Courtroom::set_font(QWidget *widget, QString class_name,
 | 
			
		||||
                                              design_file, ao_app->get_chat(p_char)) !=
 | 
			
		||||
                   "1"; // is the font anti-aliased or not?
 | 
			
		||||
 | 
			
		||||
  bool outlined = ao_app->get_design_element(p_identifier + "_outlined", design_file, ao_app->get_chat(p_char)) == "1";
 | 
			
		||||
  QColor outline_color;
 | 
			
		||||
  int outline_width = 1;
 | 
			
		||||
  if (outlined) {
 | 
			
		||||
      QString outline_color_result =
 | 
			
		||||
          ao_app->get_design_element(p_identifier + "_outline_color", design_file, ao_app->get_chat(p_char));
 | 
			
		||||
      outline_color = QColor(0,0,0);
 | 
			
		||||
      if (outline_color_result != "") {
 | 
			
		||||
        QStringList o_color_list = outline_color_result.split(",");
 | 
			
		||||
 | 
			
		||||
        if (o_color_list.size() >= 3) {
 | 
			
		||||
          outline_color.setRed(o_color_list.at(0).toInt());
 | 
			
		||||
          outline_color.setGreen(o_color_list.at(1).toInt());
 | 
			
		||||
          outline_color.setBlue(o_color_list.at(2).toInt());
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      outline_width = ao_app->get_design_element(p_identifier + "_outline_width", design_file, ao_app->get_chat(p_char)).toInt() * Options::getInstance().themeScalingFactor();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  this->set_qfont(widget, class_name,
 | 
			
		||||
                  get_qfont(font_name, f_pointsize, antialias), f_color, bold);
 | 
			
		||||
                  get_qfont(font_name, f_pointsize, antialias), f_color, bold, outlined, outline_color, outline_width);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QFont Courtroom::get_qfont(QString font_name, int f_pointsize, bool antialias)
 | 
			
		||||
@ -1207,11 +1226,18 @@ QFont Courtroom::get_qfont(QString font_name, int f_pointsize, bool antialias)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Courtroom::set_qfont(QWidget *widget, QString class_name, QFont font,
 | 
			
		||||
                          QColor f_color, bool bold)
 | 
			
		||||
                          QColor f_color, bool bold, bool outlined, QColor outline_color, int outline_width)
 | 
			
		||||
{
 | 
			
		||||
  if (class_name.isEmpty())
 | 
			
		||||
    class_name = widget->metaObject()->className();
 | 
			
		||||
 | 
			
		||||
  if (class_name == "AOChatboxLabel") { // Only shownames can be outlined
 | 
			
		||||
     ui_vp_showname->setIsOutlined(outlined);
 | 
			
		||||
     ui_vp_showname->setOutlineColor(outline_color);
 | 
			
		||||
     ui_vp_showname->setTextColor(f_color);
 | 
			
		||||
     ui_vp_showname->setOutlineWidth(outline_width);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  font.setBold(bold);
 | 
			
		||||
  widget->setFont(font);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user