~ubuntu-branches/debian/sid/kxstitch/sid

« back to all changes in this revision

Viewing changes to kxstitch/texttooldialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): eric pareja
  • Date: 2005-02-19 12:37:22 UTC
  • Revision ID: james.westby@ubuntu.com-20050219123722-kt3ru1nqvllietee
Tags: upstream-0.6
ImportĀ upstreamĀ versionĀ 0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2004 by Stephen Allewell                                *
 
3
 *   stephen@mirramar.fsnet.co.uk                                          *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 ***************************************************************************/
 
10
 
 
11
#include <qpainter.h>
 
12
#include <qlineedit.h>
 
13
#include <qspinbox.h>
 
14
#include <qpushbutton.h>
 
15
#include <qstring.h>
 
16
#include <kfontcombo.h>
 
17
#include <kapplication.h>
 
18
#include "texttooldialog.h"
 
19
#include "editview.h"
 
20
 
 
21
TextToolDialog::TextToolDialog(QWidget* parent) : TextToolDlg(parent,"TextToolDlg",true)
 
22
{
 
23
  connect(TextTool_Text,SIGNAL(textChanged(const QString&)),this,SLOT(slotTextChanged(const QString&)));
 
24
  connect(TextTool_Help,SIGNAL(clicked()),this,SLOT(slotContextHelp()));
 
25
  connect(TextTool_Font,SIGNAL(highlighted(int)),this,SLOT(slotFontSelected(int)));
 
26
  connect(TextTool_Size,SIGNAL(valueChanged(int)),this,SLOT(slotSizeChanged(int)));
 
27
  TextTool_Font->setCurrentItem(1);
 
28
  slotFontSelected(1);
 
29
  TextTool_OK->setEnabled(false);
 
30
}
 
31
 
 
32
TextToolDialog::~TextToolDialog()
 
33
{
 
34
  // nothing to do here
 
35
}
 
36
 
 
37
QByteArray TextToolDialog::pattern()
 
38
{
 
39
  QPixmap *pm = new QPixmap(1000,100,1);
 
40
  QPainter *p = new QPainter;
 
41
  p->begin(pm);
 
42
  QFont f = p->font();
 
43
  f.setFamily(m_font);
 
44
  f.setPixelSize(m_size);
 
45
  p->setFont(f);
 
46
  p->setPen(QPen(Qt::color0,1));
 
47
  QRect br = p->boundingRect(0,0,1000,100,AlignAuto,m_text);
 
48
  m_width = br.width();
 
49
  m_height = br.height();
 
50
  p->end();
 
51
  pm->resize(m_width,m_height);
 
52
  p->begin(pm);
 
53
  p->setFont(f);
 
54
  pm->fill(Qt::color0);
 
55
  p->setPen(QPen(Qt::color1,1));
 
56
  p->drawText(0,0,m_width,m_height,AlignCenter,m_text);
 
57
  p->end();
 
58
  QImage im;
 
59
  QByteArray a(m_width*m_height);
 
60
  im = pm->convertToImage();
 
61
  for (int y = 0 ; y < m_height ; y++)
 
62
    for (int x = 0 ; x < m_width ; x++)
 
63
      a[y*m_width+x] = ((im.pixelIndex(x,y))?1:0);
 
64
  delete p;
 
65
  delete pm;
 
66
  return a;
 
67
}
 
68
 
 
69
void TextToolDialog::accept()
 
70
{
 
71
  m_font = TextTool_Font->currentFont();
 
72
  m_text = TextTool_Text->text();
 
73
  m_size = TextTool_Size->value();
 
74
  m_width = 0;
 
75
  m_height = 0;
 
76
  TextToolDlg::accept();
 
77
}
 
78
 
 
79
int TextToolDialog::boundingWidth()
 
80
{
 
81
  return m_width;
 
82
}
 
83
 
 
84
int TextToolDialog::boundingHeight()
 
85
{
 
86
  return m_height;
 
87
}
 
88
 
 
89
void TextToolDialog::slotContextHelp()
 
90
{
 
91
  kapp->invokeHelp("TextDialog");
 
92
}
 
93
 
 
94
void TextToolDialog::slotTextChanged(const QString& s)
 
95
{
 
96
  TextTool_OK->setEnabled(!s.isEmpty());
 
97
}
 
98
 
 
99
void TextToolDialog::slotFontSelected(int)
 
100
{
 
101
  QFont f = TextTool_Text->font();
 
102
  f.setFamily(TextTool_Font->currentFont());
 
103
  TextTool_Text->setFont(f);
 
104
}
 
105
 
 
106
void TextToolDialog::slotSizeChanged(int s)
 
107
{
 
108
  QFont f = TextTool_Text->font();
 
109
  f.setPointSize(s);
 
110
  TextTool_Text->setFont(f);
 
111
}
 
112