Home » Community » Newbie corner » GridCtrl + rich texts
GridCtrl + rich texts [message #36973] |
Thu, 02 August 2012 14:29 |
idkfa46
Messages: 155 Registered: December 2011
|
Experienced Member |
|
|
Hello guys,
is it possibile to active QTF format inside GridCtrl grid?
I'd like to use Superscript['] and Subscript [,] that's working fine on layouts but not inside grid...
[` superscript]
[, subscript]
any suggestion?
thanks,
Matteo
|
|
|
|
Re: GridCtrl + rich texts [message #36982 is a reply to message #36973] |
Fri, 03 August 2012 21:39 |
Sender Ghost
Messages: 301 Registered: November 2008
|
Senior Member |
|
|
Hello, Matteo.
idkfa46 wrote on Thu, 02 August 2012 14:29 | Is it possibile to active QTF format inside GridCtrl grid?
|
Yes, it's possible to create special GridQTFDisplay class (inherited from GridDisplay), which uses QTFDisplay Paint function.
#include <GridCtrl/GridCtrl.h>
#include <RichText/RichText.h>
using namespace Upp;
class GridQTFDisplay : public GridDisplay {
public:
virtual void Paint(Draw& w, int x, int y, int cx, int cy, const Value& val, dword style,
Color& fg, Color& bg, Font& fnt, bool found, int fs, int fe)
{
QTFDisplay().Paint(w, RectC(x, y, cx, cy), val, fg, bg, style);
}
};
class App : public TopWindow {
public:
typedef App CLASSNAME;
App();
GridCtrl list;
};
App::App()
{
Title("GridCtrl with QTF Display");
Sizeable().Zoomable();
const Size sz(480, 320);
SetRect(sz); SetMinSize(sz);
list.Chameleon();
list.AddColumn("x", 10);
list.AddColumn("y", 10);
list.AddColumn("Equation", 50).SetDisplay(Single<GridQTFDisplay>()).HeaderAlignCenter();
list.AddColumn("Equal");
for (int i = 0, x = 1, y = 2; i <= 10; ++i, ++x, ++y)
list.Add(x, y, Format("[= [1 (x + y)][` %d][1 = %d][` %d]]", i, x + y, i),
pow(double(x + y), i));
Add(list.VSizePosZ(4, 4).HSizePosZ(4, 4));
}
GUI_APP_MAIN
{
App app;
app.Run();
}
[Updated on: Fri, 03 August 2012 23:16] Report message to a moderator
|
|
|
|
|
Re: GridCtrl + rich texts [message #36988 is a reply to message #36987] |
Sun, 05 August 2012 01:53 |
Sender Ghost
Messages: 301 Registered: November 2008
|
Senior Member |
|
|
idkfa46 wrote on Sun, 05 August 2012 00:38 | I was trying to change column alignment (with QTFDisplay) by .AlignLeft() but nothing happen ... It's always at center
|
Technically, the GridQTFDisplay class forwarding GridDisplay Paint function through QTFDisplay Paint function, which doesn't use information about style variable, therefore GridCtrl align functions not applicable here.
Just use QTF paragraph formatting, e.g. "[< Left]", "[= Center]", "[> Right]", but "<" is by default (and not necessary for this case).
Now, you could understand why it was on the center.
[Updated on: Sun, 05 August 2012 02:26] Report message to a moderator
|
|
|
|
Re: GridCtrl + rich texts [message #36992 is a reply to message #36990] |
Sun, 05 August 2012 15:51 |
Sender Ghost
Messages: 301 Registered: November 2008
|
Senior Member |
|
|
Hello, Luigi.
forlano wrote on Sun, 05 August 2012 12:32 | I guess it should work for ArrayCtrl too.
|
Yes, QTFDisplayCls, which inherited from Display, could be used inside many Ctrls, which supports SetDisplay function with Display argument, e.g. ArrayCtrl, ColumnList, DropList, TreeCtrl, etc.
Toggle Spoiler
#include <CtrlLib/CtrlLib.h>
#include <RichText/RichText.h>
using namespace Upp;
class App : public TopWindow {
public:
typedef App CLASSNAME;
App();
ArrayCtrl list;
};
App::App()
{
Title("ArrayCtrl with QTF Display");
Sizeable().Zoomable();
const Size sz(480, 340);
SetRect(sz); SetMinSize(sz);
list.AutoHideSb();
list.SetLineCy(Draw::GetStdFont().GetCy() + 8);
list.AddColumn("QTF");
list.AddColumn("QTF Display").SetDisplay(QTFDisplay());
const String qtf("[1 [* (]x + y[* )]][` %d]");
for (int i = 0; i <= 10; ++i) {
const String text(Format(qtf, i));
list.Add(text, text);
}
Add(list.VSizePosZ(4, 4).HSizePosZ(4, 4));
}
GUI_APP_MAIN
{
App app;
app.Run();
}
forlano wrote on Sun, 05 August 2012 12:32 | I vote to move this example in the reference or examples assembly.
|
I agree (with some variation of contents). But this is undocumented functionality and question to developer(s) of RichText U++ package.
Edit: Fixed QTF formatted text.
[Updated on: Thu, 09 August 2012 15:43] Report message to a moderator
|
|
|
|
|
Re: GridCtrl + rich texts [message #37000 is a reply to message #36973] |
Tue, 07 August 2012 02:35 |
Sender Ghost
Messages: 301 Registered: November 2008
|
Senior Member |
|
|
I thought about generalized way to access Display through GridDisplay and made following example with templates:
Toggle Spoiler
#include <GridCtrl/GridCtrl.h>
#include <RichText/RichText.h>
using namespace Upp;
template <const Display& (*DisplayFn)()>
class DisplayToGrid : public GridDisplay {
protected:
const Display& display;
public:
DisplayToGrid() : display(DisplayFn()) {}
virtual void Paint(Draw& w, int x, int y, int cx, int cy, const Value& val, dword style,
Color& fg, Color& bg, Font& fnt, bool found, int fs, int fe)
{
display.Paint(w, RectC(x, y, cx, cy), val, fg, bg, style);
}
};
template <const Display& (*DisplayFn)()>
GridDisplay& SingleDisplayToGrid()
{
return Single<DisplayToGrid<DisplayFn> >();
}
class DisplayGrid : public GridDisplay {
protected:
const Display *display;
public:
DisplayGrid() : display(NULL) {}
DisplayGrid(const Display& d) : display(&d) {}
void SetDisplay(const Display& d) { display = &d; }
const Display& GetDisplay() { return *display; }
virtual void Paint(Draw& w, int x, int y, int cx, int cy, const Value& val, dword style,
Color& fg, Color& bg, Font& fnt, bool found, int fs, int fe)
{
if (display)
display->Paint(w, RectC(x, y, cx, cy), val, fg, bg, style);
}
};
class CustomDisplayWithIcon : public DisplayWithIcon {
public:
virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const
{
w.DrawRect(r, paper);
DisplayWithIcon::Paint(w, r, q, ink, paper, style);
}
};
typedef GridDisplay& (*SingleDisplay)();
Tuple3<String, String, SingleDisplay> display[] = {
"StdDisplay", "Left aligned text", SingleDisplayToGrid<StdDisplay>,
"StdCenterDisplay", "Center aligned text", SingleDisplayToGrid<StdCenterDisplay>,
"StdRightDisplay", "Right aligned text", SingleDisplayToGrid<StdRightDisplay>,
"QTFDisplay", "[G1= [* bold], [/ italic], [- strikeout], [_ underline], [_-*/ all previous]]",
SingleDisplayToGrid<QTFDisplay>
};
const int displayCount = __countof(display);
class App : public TopWindow {
public:
typedef App CLASSNAME;
App();
GridCtrl list;
};
App::App()
{
Title("GridCtrl Display Example");
Sizeable().Zoomable();
const Size sz(640, 320);
SetRect(sz); SetMinSize(sz);
list.Chameleon();
list.AddColumn("Display").Fixed(120);
list.AddColumn("Example");
for (int i = 0; i < displayCount; ++i) {
list.Add(display[i].a, display[i].b);
list.GetCell(i, 1).SetDisplay(display[i].c());
}
int count = displayCount;
list.Add("ColorDisplay", Blend(LtGreen(), Magenta())).GetCell(count++, 1).SetDisplay(SingleDisplayToGrid<ColorDisplay>());
list.Add("ImageDisplay", CtrlImg::checkers()).GetCell(count++, 1).SetDisplay(SingleDisplayToGrid<ImageDisplay>());
list.Add("FittedImageDisplay", CtrlImg::checkers()).GetCell(count++, 1).SetDisplay(SingleDisplayToGrid<FittedImageDisplay>());
// And complex example about how to integrate GridDisplay with Display, while using their custom functions.
CustomDisplayWithIcon& dwi = Single<CustomDisplayWithIcon>();
dwi.SetIcon(CtrlImg::go_forward());
dwi.SetDisplay(StdCenterDisplay());
DisplayGrid& dg = Single<DisplayGrid>();
dg.SetDisplay(dwi);
list.Add("CustomDisplayWithIcon", "Center aligned text with icon").GetCell(count, 1).SetDisplay(dg);
Add(list.VSizePosZ(4, 4).HSizePosZ(4, 4));
}
GUI_APP_MAIN
{
App app;
app.Run();
}
Edit: Replaced DisplayWithIcon with CustomDisplayWithIcon class, which draws background rectangle to fix icon drawing issue (and possibly other Display without background rectangle) on GridCtrl cell. Optimized DisplayToGrid initialization.
[Updated on: Sat, 11 August 2012 14:04] Report message to a moderator
|
|
|
|
Re: GridCtrl + rich texts [message #37024 is a reply to message #37023] |
Thu, 09 August 2012 15:14 |
Sender Ghost
Messages: 301 Registered: November 2008
|
Senior Member |
|
|
forlano wrote on Thu, 09 August 2012 13:48 | I wonder how this class interact with the AsQtf() method of ArrayCtrl.
|
If you meant GridDisplay based classes, then they not related to ArrayCtrl, because it uses Display based classes. Moreover, Display and GridDisplay classes used to render input Value. Therefore, they not interact with AsQtf method of ArrayCtrl.
I tested AsQtf method of ArrayCtrl with QTF formatted texts and its (correct) output works inside QTF designer of TheIDE.
Further, I tested QTF formatted texts for examples inside this topic. And I found one mistake:
[1 [* (]x + y[* )]]][` %d]
which I fixed to:
[1 [* (]x + y[* )]][` %d]
[Updated on: Thu, 09 August 2012 15:43] Report message to a moderator
|
|
|
|
Re: GridCtrl + rich texts [message #37028 is a reply to message #37026] |
Thu, 09 August 2012 20:42 |
Sender Ghost
Messages: 301 Registered: November 2008
|
Senior Member |
|
|
forlano wrote on Thu, 09 August 2012 19:17 | I meant the class equivalent of GridDisplay but for ArrayCtrl. There we have for free the AsQtf method. So what we will see on the screen will be rendered in a qtf document as well.
|
Sorry about my wrong guess. Seems like, I thought about reply message instead of this one first.
forlano wrote on Thu, 09 August 2012 19:17 | If I have understood it should work.
|
Paraphrasing, yes, the QTFDisplayCls class (also) works inside ArrayCtrl and its correct input Value creates correct output inside AsQtf method.
By input Value I meant QTF formatted text. Without QTFDisplayCls you will see not preprocessed QTF formatted text, but inside QTF designer you will see preprocessed output without reference to applied (or not applied) QTFDisplayCls class.
I fixed some issues after your message.
Thank you too.
[Updated on: Thu, 09 August 2012 22:01] Report message to a moderator
|
|
|
|
|
Re: GridCtrl + rich texts [message #50395 is a reply to message #36982] |
Sun, 14 October 2018 13:34 |
|
deep
Messages: 265 Registered: July 2011 Location: Bangalore
|
Experienced Member |
|
|
Sender Ghost wrote on Sat, 04 August 2012 01:09Hello, Matteo.
idkfa46 wrote on Thu, 02 August 2012 14:29Is it possibile to active QTF format inside GridCtrl grid?
Yes, it's possible to create special GridQTFDisplay class (inherited from GridDisplay), which uses QTFDisplay Paint function.
#include <GridCtrl/GridCtrl.h>
#include <RichText/RichText.h>
using namespace Upp;
class GridQTFDisplay : public GridDisplay {
public:
virtual void Paint(Draw& w, int x, int y, int cx, int cy, const Value& val, dword style,
Color& fg, Color& bg, Font& fnt, bool found, int fs, int fe)
{
QTFDisplay().Paint(w, RectC(x, y, cx, cy), val, fg, bg, style);
}
};
class App : public TopWindow {
public:
typedef App CLASSNAME;
App();
GridCtrl list;
};
App::App()
{
Title("GridCtrl with QTF Display");
Sizeable().Zoomable();
const Size sz(480, 320);
SetRect(sz); SetMinSize(sz);
list.Chameleon();
list.AddColumn("x", 10);
list.AddColumn("y", 10);
list.AddColumn("Equation", 50).SetDisplay(Single<GridQTFDisplay>()).HeaderAlignCenter();
list.AddColumn("Equal");
for (int i = 0, x = 1, y = 2; i <= 10; ++i, ++x, ++y)
list.Add(x, y, Format("[= [1 (x + y)][` %d][1 = %d][` %d]]", i, x + y, i),
pow(double(x + y), i));
Add(list.VSizePosZ(4, 4).HSizePosZ(4, 4));
}
GUI_APP_MAIN
{
App app;
app.Run();
}
In this example also QTF color not working. All other attributes working.
[@G ...] and [$Y ...]
Warm Regards
Deepak
|
|
|
Re: GridCtrl + rich texts [message #50396 is a reply to message #50395] |
Mon, 15 October 2018 11:43 |
|
deep
Messages: 265 Registered: July 2011 Location: Bangalore
|
Experienced Member |
|
|
Hi
I have done this. Which is working for me for GridCtrl.
It is not elegant but working.
Color in QFT must be given as "[@(nn.nn.nn) " or "[$(nn.nn.nn) "
class Gridqtfdisplay : public GridDisplay
{
public:
virtual void Paint ( Draw& w, int x, int y, int cx, int cy, const Value& val, dword style,
Color& fg, Color& bg, Font& fnt, bool found, int fs, int fe )
{
String s;
s = val;
RegExp r1 ( "(\\[([\\@\\$])\\((\\d+)\\.(\\d+)\\.(\\d+)\\))", RegExp::UNICODE );
while ( r1.GlobalMatch ( s ) )
{
if ( r1[1] == "@" )
fg = Color ( StrInt ( r1[2] ), StrInt ( r1[3] ), StrInt ( r1[4] ) );
if ( r1[1] == "$" )
bg = Color ( StrInt ( r1[2] ), StrInt ( r1[3] ), StrInt ( r1[4] ) );
}
QTFDisplay().Paint ( w, RectC ( x, y, cx, cy ), val, fg, bg, style );
}
};
Warm Regards
Deepak
|
|
|
Goto Forum:
Current Time: Fri Sep 20 09:09:54 CEST 2024
Total time taken to generate the page: 0.02946 seconds
|