Class WQrCode
- java.lang.Object
-
- Direct Known Subclasses:
TotpQrCode
public class WQrCode extends WPaintedWidget
A widget representing a QR code.This widget allows to generate QR code from a string.
If you wish to alter the look of the QR code (to add a logo in the middle for instance), you can override paintEvent. However, you will still need to call the
paintEvent()to generate the QR code itself.The content that is encoded is taken as-is. If the purpose of your QR code requires special formatting, the formatted string needs to be supplied to the constructor.
By default, the generated QR code will use the lowest possible error correction, and a square size of 5 pixels.
Usage example:
String website = "https://webtoolkit.eu"; WApplication app = WApplication.getInstance(); app.getRoot().addWidget(new WQrCode(website));
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWQrCode.ErrorCorrectionLevelRepresents the different error correction levels for QR codes.-
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
-
Field Summary
-
Fields inherited from class eu.webtoolkit.jwt.WInteractWidget
dragTouchEndSlot_, dragTouchSlot_, noDefault
-
Fields inherited from class eu.webtoolkit.jwt.WWidget
WT_GETEXTRAMS_JS
-
-
Constructor Summary
Constructors Constructor Description WQrCode()Creates a default QR code with an empty message.WQrCode(WContainerWidget parentContainer)Creates a default QR code with an empty message.WQrCode(java.lang.String message)Creates a QR code.WQrCode(java.lang.String message, double squareSize)Creates a QR code.WQrCode(java.lang.String message, double squareSize, WContainerWidget parentContainer)Creates a QR code.WQrCode(java.lang.String message, WQrCode.ErrorCorrectionLevel ecl)Creates a QR code.WQrCode(java.lang.String message, WQrCode.ErrorCorrectionLevel ecl, double squareSize)Creates a QR code.WQrCode(java.lang.String message, WQrCode.ErrorCorrectionLevel ecl, double squareSize, WContainerWidget parentContainer)Creates a QR code.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WBrushgetBrush()Returns the brush with which the QR code is painted.WQrCode.ErrorCorrectionLevelgetErrorCorrectionLevel()Returns the error correction level of the QR code.java.lang.StringgetMessage()Returns the message of the QR code.doublegetSquareSize()Returns the size of the squares composing the QR code.booleanisError()Returns whether an error stopped the generation of the QR code.protected voidpaintEvent(WPaintDevice paintDevice)Paints the widget.voidsetBrush(WBrush brush)Sets the brush with which the QR code is painted.voidsetErrorCorrectionLevel(WQrCode.ErrorCorrectionLevel ecl)Set the error correction level of the QR code.voidsetMessage(java.lang.String message)Set the message of the QR code.voidsetSquareSize(double size)Set the size of the dots composing the QR code.-
Methods inherited from class eu.webtoolkit.jwt.WPaintedWidget
addArea, createDomElement, createJSBrush, createJSPainterPath, createJSPen, createJSPoint, createJSRect, createJSTransform, enableAjax, getArea, getAreas, getBotResourceId, getCreatePaintDevice, getDomChanges, getMethod, getObjJsRef, getPreferredMethod, getRepaintSlot, insertArea, layoutSizeChanged, refresh, remove, removeArea, render, resize, setBotResourceId, setFormData, setPreferredMethod, update, update, update
-
Methods inherited from class eu.webtoolkit.jwt.WInteractWidget
clicked, doubleClicked, enterPressed, escapePressed, gestureChanged, gestureEnded, gestureStarted, getMouseOverDelay, isEnabled, keyPressed, keyWentDown, keyWentUp, load, mouseDragged, mouseMoved, mouseWentDown, mouseWentOut, mouseWentOver, mouseWentUp, mouseWheel, propagateSetEnabled, setDraggable, setDraggable, setDraggable, setDraggable, setMouseOverDelay, setPopup, touchEnded, touchMoved, touchStarted, unsetDraggable
-
Methods inherited from class eu.webtoolkit.jwt.WWebWidget
addStyleClass, beingDeleted, blurred, callJavaScriptMember, childrenChanged, doJavaScript, escapeText, escapeText, escapeText, escapeText, find, findById, focussed, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getFloatSide, getHeight, getHtmlTagName, getId, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getTabIndex, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, hideToolTip, isCanReceiveFocus, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, iterateChildren, jsStringLiteral, jsStringLiteral, manageWidget, parentResized, parentResized, propagateSetVisible, removeScript, removeStyleClass, scrollVisibilityChanged, setAttributeValue, setBaseZIndex, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setDisabled, setFlexBox, setFloatSide, setFocus, setHidden, setHiddenKeepsGeometry, setHtmlTagName, setId, setInline, setJavaScriptMember, setLineHeight, setLoadLaterWhenInvisible, setMargin, setMaximumSize, setMinimumSize, setObjectName, setOffsets, setParentWidget, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignment, showToolTip, showToolTipOnHover, unescapeText, updateSignalConnection, voidEventSignal, widgetAdded, widgetRemoved
-
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, applyThemeStyles, boxBorder, boxPadding, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, needsRerender, positionAt, positionAt, positionAt, positionAt, removeFromParent, removeStyleClass, removeWidget, render, resize, scheduleRender, scheduleRender, scheduleRender, scheduleThemeStyleApply, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
-
Methods inherited from class eu.webtoolkit.jwt.WObject
getObjectName
-
-
-
-
Constructor Detail
-
WQrCode
public WQrCode(WContainerWidget parentContainer)
Creates a default QR code with an empty message.
-
WQrCode
public WQrCode()
Creates a default QR code with an empty message.
-
WQrCode
public WQrCode(java.lang.String message, double squareSize, WContainerWidget parentContainer)Creates a QR code.Create a QR code with the given message, and square size.
-
WQrCode
public WQrCode(java.lang.String message, double squareSize)Creates a QR code.
-
WQrCode
public WQrCode(java.lang.String message, WQrCode.ErrorCorrectionLevel ecl, double squareSize, WContainerWidget parentContainer)Creates a QR code.Create a QR code with the given message, error correction level and square size.
-
WQrCode
public WQrCode(java.lang.String message)
Creates a QR code.Calls
this(message, WQrCode.ErrorCorrectionLevel.LOW, 5.0, (WContainerWidget)null)
-
WQrCode
public WQrCode(java.lang.String message, WQrCode.ErrorCorrectionLevel ecl)Creates a QR code.
-
WQrCode
public WQrCode(java.lang.String message, WQrCode.ErrorCorrectionLevel ecl, double squareSize)Creates a QR code.Calls
this(message, ecl, squareSize, (WContainerWidget)null)
-
-
Method Detail
-
setErrorCorrectionLevel
public void setErrorCorrectionLevel(WQrCode.ErrorCorrectionLevel ecl)
Set the error correction level of the QR code.Increases the amount of information that can be lost before altering the encoded message. A higher level of error correcting code, makes the QR code more robust to changes.
Increasing the error correction level also increases the amount of data needed to encode the message, resulting in a visually bigger QR code than one with a lower error correcting level.
By default,
LOWis used.- See Also:
setMessage(String message)
-
getErrorCorrectionLevel
public WQrCode.ErrorCorrectionLevel getErrorCorrectionLevel()
Returns the error correction level of the QR code.
-
setMessage
public void setMessage(java.lang.String message)
Set the message of the QR code.This sets the message carried by the QR code. There is a limit to the size of the message which depends on many factors. The most important one is the error correction level. Higher error correction level diminish the maximum size the message can have. Roughly speaking when using the highest level of error correction, the maximum number of allowed content is in the area of 1Kb, whereas for the lowest level of error correction, this is around 3Kb.
The longer the message is, the more data needs to be encoded, and thus the bigger the resulting QR code becomes.
If the message is to long, the QR code will not be generated.
-
getMessage
public java.lang.String getMessage()
Returns the message of the QR code.- See Also:
setMessage(String message)
-
setSquareSize
public void setSquareSize(double size)
Set the size of the dots composing the QR code.Sets the size (in pixels) that each dot of the QR code will have. A single square of the QR code can be seen in any corner of the QR code. There a reference visual is always displayed that contains exactly seven dots in width and height.
This allows the application to correctly resize the QR code.
-
getSquareSize
public double getSquareSize()
Returns the size of the squares composing the QR code.- See Also:
setSquareSize(double size)
-
isError
public boolean isError()
Returns whether an error stopped the generation of the QR code.Returns true if the QR code could not be generated due to an error.
In case the QR code was not generated, it's size will be set to 0 and the QR code will not be painted.
-
setBrush
public void setBrush(WBrush brush)
Sets the brush with which the QR code is painted.This allows for the color of the QR code to be changed.
-
getBrush
public WBrush getBrush()
Returns the brush with which the QR code is painted.- See Also:
setBrush(WBrush brush)
-
paintEvent
protected void paintEvent(WPaintDevice paintDevice)
Description copied from class:WPaintedWidgetPaints the widget.You should reimplement this method to paint the contents of the widget, using the given paintDevice.
- Specified by:
paintEventin classWPaintedWidget
-
-